「選択範囲を上下に移動」の版間の差分
ナビゲーションに移動
検索に移動
ページの作成:「= 概要 = 選択されている範囲を 1 行上下します.<br> (某所よりログが流れてしまうため待避) = コード = == 下へ移動 == <sourc...」 |
編集の要約なし |
||
| 1行目: | 1行目: | ||
= 概要 = | = 概要 = | ||
選択されている範囲を 1 行上下します. | 選択されている範囲を 1 行上下します. | ||
== 変更履歴 == | |||
* 2013/4/9 ブックマークがずれるのを修正 | |||
= コード = | = コード = | ||
== | == 選択範囲を上へ移動 == | ||
<source lang="javascript"> | <source lang="javascript"> | ||
#title="選択範囲を上へ移動" | |||
var s = Document.Selection; | var s = Document.Selection; | ||
var ty = s.GetTopPointY(mePosLogical); | var ty = s.GetTopPointY(mePosLogical); | ||
var by = s.GetBottomPointY(mePosLogical); | var by = s.GetBottomPointY(mePosLogical); | ||
if (Document | if (ty > 1) { | ||
SelectLine(s, ty, by | Redraw = false; | ||
var sx = ScrollX, sy = ScrollY; | |||
// ブックマークの待避 | |||
var bookmarkList = GetBookmarkList(Document, ty-1, by, true); | |||
// 選択行を上へ移動 | |||
SelectLine(s, ty-1, by); | |||
var a = s.Text.split("\n"); | var a = s.Text.split("\n"); | ||
a. | a.push(a.shift()); | ||
s.Text = a.join("\n"); | s.Text = a.join("\n"); | ||
SelectLine(s, ty | |||
// ブックマークの復元 | |||
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) { | function SelectLine(s, ty, by) { | ||
s.SetAnchorPoint(mePosLogical, 1, ty); | s.SetAnchorPoint(mePosLogical, 1, ty); | ||
s.SetActivePoint(mePosLogical, 1, by, true); | s.SetActivePoint(mePosLogical, 1, by, true); | ||
s.EndOfLine(true, mePosLogical); | 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; | |||
} | } | ||
</source> | </source> | ||
== | == 選択範囲を下へ移動 == | ||
<source lang="javascript"> | <source lang="javascript"> | ||
#title="選択範囲を下へ移動" | |||
var s = Document.Selection; | var s = Document.Selection; | ||
var ty = s.GetTopPointY(mePosLogical); | var ty = s.GetTopPointY(mePosLogical); | ||
var by = s.GetBottomPointY(mePosLogical); | var by = s.GetBottomPointY(mePosLogical); | ||
if (ty | if (Document.GetLines(0) > by) { | ||
SelectLine(s, ty | Redraw = false; | ||
var sx = ScrollX, sy = ScrollY; | |||
// ブックマークの待避 | |||
var bookmarkList = GetBookmarkList(Document, ty, by+1, true); | |||
// 選択行を下へ移動 | |||
SelectLine(s, ty, by+1); | |||
var a = s.Text.split("\n"); | var a = s.Text.split("\n"); | ||
a. | a.unshift(a.pop()); | ||
s.Text = a.join("\n"); | s.Text = a.join("\n"); | ||
SelectLine(s, ty | |||
// ブックマークの復元 | |||
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) { | function SelectLine(s, ty, by) { | ||
s.SetAnchorPoint(mePosLogical, 1, ty); | s.SetAnchorPoint(mePosLogical, 1, ty); | ||
s.SetActivePoint(mePosLogical, 1, by, true); | s.SetActivePoint(mePosLogical, 1, by, true); | ||
s.EndOfLine(true, mePosLogical); | 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; | |||
} | |||
</source> | </source> | ||
2013年4月9日 (火) 22:45時点における版
概要
選択されている範囲を 1 行上下します.
変更履歴
- 2013/4/9 ブックマークがずれるのを修正
コード
選択範囲を上へ移動
#title="選択範囲を上へ移動"
var s = Document.Selection;
var ty = s.GetTopPointY(mePosLogical);
var by = s.GetBottomPointY(mePosLogical);
if (ty > 1) {
Redraw = false;
var sx = ScrollX, 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;
}
選択範囲を下へ移動
#title="選択範囲を下へ移動"
var s = Document.Selection;
var ty = s.GetTopPointY(mePosLogical);
var by = s.GetBottomPointY(mePosLogical);
if (Document.GetLines(0) > by) {
Redraw = false;
var sx = ScrollX, 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;
}
スポンサーリンク