「降順で並び替え」の版間の差分

提供: MeryWiki
ナビゲーションに移動 検索に移動
MSY-07 (トーク | 投稿記録)
スペースからタブに変更
MSY-07 (トーク | 投稿記録)
ソースコードの最適化
13行目: 13行目:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------


if (document.selection.Text == "") {
var sel = document.selection;
document.selection.SelectAll();
if (sel.Text == "") {
sel.SelectAll();
}
}
document.selection.Text = document.selection.Text.split("\n").sort(
sel.Text = sel.Text.split("\n").sort(
function(a, b) {
function(a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
}
).join("\n");
).join("\n");
document.selection.StartOfDocument();
sel.StartOfDocument();
</syntaxhighlight>
</syntaxhighlight>

2024年12月31日 (火) 03:00時点における版

このマクロはMeryのMacrosフォルダに同梱されています。

概要

編集中の文書の行を降順で並べ替えます。

ソースコード

// -----------------------------------------------------------------------------
// 降順で並べ替え
//
// Copyright (c) Kuro. All Rights Reserved.
// www:    https://www.haijin-boys.com/
// -----------------------------------------------------------------------------

var sel = document.selection;
if (sel.Text == "") {
	sel.SelectAll();
}
sel.Text = sel.Text.split("\n").sort(
	function(a, b) {
		return ((a < b) ? 1 : ((a > b) ? -1 : 0));
	}
).join("\n");
sel.StartOfDocument();
スポンサーリンク