「Markdown 向け、タスクリスト (* []) のチェック状態をトグル」の版間の差分
編集の要約なし |
SyntaxHighlightにcopyの追加 |
||
| (2人の利用者による、間の3版が非表示) | |||
| 3行目: | 3行目: | ||
複数行選択及びマルチカーソル機能に対応しています。 | 複数行選択及びマルチカーソル機能に対応しています。 | ||
< | <syntaxhighlight lang="javascript" copy> | ||
#title = | #title = "Markdown タスクリストのチェックをトグル" | ||
Redraw = false; | Redraw = false; | ||
BeginUndoGroup(); | BeginUndoGroup(); | ||
| 62行目: | 62行目: | ||
s = d.selection; | s = d.selection; | ||
s.Mode = meModeMulti; | s.Mode = meModeMulti; | ||
// | // (1) まず、GetActivePos と GetAnchorPos で複数選択のリストを作成します | ||
var selections = [{s: s.GetAnchorPos(), e: s.GetActivePos()}]; | var selections = [{s: s.GetAnchorPos(), e: s.GetActivePos()}]; | ||
if (s.Count > 0) { | if (s.Count > 0) { | ||
| 72行目: | 72行目: | ||
var q = 0; | var q = 0; | ||
for (var i = 0; i < selections.length; i++) { | for (var i = 0; i < selections.length; i++) { | ||
// | // (2) そのリストを上から順に SetActivePos で、「シングルカーソル」で範囲選択します。この段階で複数選択は解除され、通常のマクロ操作が可能となります | ||
s.SetActivePos(selections[i].s + p); | s.SetActivePos(selections[i].s + p); | ||
s.SetActivePos(selections[i].e + p, true); | s.SetActivePos(selections[i].e + p, true); | ||
q = d.TextLength; | q = d.TextLength; | ||
// | // (3) <ここで通常のマクロの機能を使って普通に編集などを行います> | ||
fn(); | fn(); | ||
p += d.TextLength - q; | p += d.TextLength - q; | ||
// | // (4) 処理を行った後の選択範囲をリストに反映し、これをリストの最後まで繰り返します | ||
selections[i] = {s: s.GetAnchorPos(), e: s.GetActivePos()}; | selections[i] = {s: s.GetAnchorPos(), e: s.GetActivePos()}; | ||
} | } | ||
// | // (5) そのリストを上から順に document.selection.AddPos(StartPos, EndPos) で複数選択として復元します | ||
for (var i = 0; i < selections.length; i++) | for (var i = 0; i < selections.length; i++) | ||
s.AddPos(selections[i].s, selections[i].e); | s.AddPos(selections[i].s, selections[i].e); | ||
} | } | ||
</ | </syntaxhighlight> | ||
スポンサーリンク