ホーム
ヘルプ
よくある質問
マクロリファレンス
マクロライブラリ
プラグインライブラリ
構文ファイル
テーマ
寄付・開発支援
開発室
開発者のブログ
ログイン
設定
MeryWiki について
免責事項
MeryWiki
検索
「
選択範囲を上下に移動
」を編集中
警告:
ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。
ログイン
または
アカウントを作成
すれば、あなたの編集はその利用者名とともに表示されるほか、さまざまなメリットもあります。
スパム攻撃防止用のチェックです。 決して、ここには、値の入力は
しない
でください!
== 概要 == 選択されている範囲を1行上下します。 == 変更履歴 == * 1.0.1 (2013-04-09) ** ブックマークがずれるのを修正 * 1.0.0 (2013-03-15) ** 初版 == ソースコード == === 選択範囲を上へ移動 === <syntaxhighlight lang="javascript" copy> #title = "選択範囲を上へ移動" var s = document.selection; var ty = s.GetTopPointY(mePosLogical); var by = s.GetBottomPointY(mePosLogical); var bx = s.GetBottomPointX(mePosLogical); // 選択範囲の末尾が行頭にあるときの調整 if (ty != by && bx == 1) { by--; } if (ty > 1) { Redraw = false; var sx = ScrollX; var sy = ScrollY; // ブックマークの待避 var bookmarkList = GetBookmarkList(document, ty - 1, by, true); // 選択行を上へ移動 SelectLine(s, ty - 1, by); var a = s.Text.split("\n"); a.push(a.shift()); s.Text = a.join("\n"); // ブックマークの復元 for (var i = 0; i < bookmarkList.length; i++) { var y = bookmarkList[i] - 1; if (y == ty - 2) { y = by; } s.SetActivePoint(mePosLogical, 1, y); s.SetBookmark(); } // 選択の復元 ScrollX = sx; ScrollY = sy; SelectLine(s, ty - 1, by - 1); Redraw = true; } function SelectLine(s, ty, by) { s.SetAnchorPoint(mePosLogical, 1, ty); s.SetActivePoint(mePosLogical, 1, by, true); s.EndOfLine(true, mePosLogical); } // ブックマークの一覧を論理行単位で取得 // キャレットおよびスクロール位置が変更されるため必要なら待避 function GetBookmarkList(doc, top, bottom, isClear) { var lines = doc.GetLines(0); top = (top == null || top < 1) ? 1 : top; bottom = (bottom == null || bottom > lines) ? lines : bottom; var s = doc.selection; var b = []; if (lines == 1) { s.SetActivePoint(mePosLogical, 2, 1); if (s.PreviousBookmark()) { b.push(1); } return b; } if (top == 1) { s.SetActivePoint(mePosLogical, 1, 2); if (s.PreviousBookmark()) { b.push(1); } } s.SetActivePoint(mePosLogical, 1, top - 1); while (s.NextBookmark()) { var y = s.GetActivePointY(mePosLogical); if (y > bottom) { break; } b.push(y); if (isClear) { s.ClearBookmark(); } } return b; } </syntaxhighlight> === 選択範囲を下へ移動 === <syntaxhighlight lang="javascript" copy> #title = "選択範囲を下へ移動" var s = document.selection; var ty = s.GetTopPointY(mePosLogical); var by = s.GetBottomPointY(mePosLogical); var bx = s.GetBottomPointX(mePosLogical); // 選択範囲の末尾が行頭にあるときの調整 if (ty != by && bx == 1) { by--; } if (document.GetLines(0) > by) { Redraw = false; var sx = ScrollX; var sy = ScrollY; // ブックマークの待避 var bookmarkList = GetBookmarkList(document, ty, by + 1, true); // 選択行を下へ移動 SelectLine(s, ty, by + 1); var a = s.Text.split("\n"); a.unshift(a.pop()); s.Text = a.join("\n"); // ブックマークの復元 for (var i = 0; i < bookmarkList.length; i++) { var y = bookmarkList[i] + 1; if (y == by + 2) { y = ty; } s.SetActivePoint(mePosLogical, 1, y); s.SetBookmark(); } // 選択の復元 ScrollX = sx; ScrollY = sy; SelectLine(s, ty + 1, by + 1); Redraw = true; } function SelectLine(s, ty, by) { s.SetAnchorPoint(mePosLogical, 1, ty); s.SetActivePoint(mePosLogical, 1, by, true); s.EndOfLine(true, mePosLogical); } // ブックマークの一覧を論理行単位で取得 // キャレットおよびスクロール位置が変更されるため必要なら待避 function GetBookmarkList(doc, top, bottom, isClear) { var lines = doc.GetLines(0); top = (top == null || top < 1) ? 1 : top; bottom = (bottom == null || bottom > lines) ? lines : bottom; var s = doc.selection; var b = []; if (lines == 1) { s.SetActivePoint(mePosLogical, 2, 1); if (s.PreviousBookmark()) { b.push(1); } return b; } if (top == 1) { s.SetActivePoint(mePosLogical, 1, 2); if (s.PreviousBookmark()) { b.push(1); } } s.SetActivePoint(mePosLogical, 1, top - 1); while (s.NextBookmark()) { var y = s.GetActivePointY(mePosLogical); if (y > bottom) { break; } b.push(y); if (isClear) { s.ClearBookmark(); } } return b; } </syntaxhighlight>
編集内容の要約:
MeryWikiへの投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細は
MeryWiki:著作権
を参照)。
著作権保護されている作品は、許諾なしに投稿しないでください!
このページを編集するには、下記の数式を計算してその答えを欄に入力してください (
ヘルプ
):
いちたすには =
キャンセル
編集ヘルプ
(新しいウィンドウで開きます)
スポンサーリンク