「上に行挿入」の版間の差分

提供: MeryWiki
ナビゲーションに移動 検索に移動
Yuko (トーク | 投稿記録)
ページの作成:「現在行の上に行挿入します。 Shift + Enter や Ctrl + Shift + Enter に割り当てると便利です。 <source lang="javascript"> #title="上に行挿入" B...」
 
MSY-07 (トーク | 投稿記録)
SyntaxHighlightにcopyの追加
 
(2人の利用者による、間の6版が非表示)
1行目: 1行目:
現在行の上に行挿入します。 Shift + Enter や Ctrl + Shift + Enter に割り当てると便利です。
現在行の上に行挿入します。Shift + Enter や Ctrl + Shift + Enter に割り当てると便利です。


<source lang="javascript">
<syntaxhighlight lang="javascript" copy>
#title="上に行挿入"
#title="上に行挿入"
BeginUndoGroup();
Redraw = false;
Redraw = false;


11行目: 10行目:
var insertIndent = true;
var insertIndent = true;


selection = Document.Selection;
var selection = Document.Selection;
var ay = selection.GetActivePointY(mePosLogical);
var activeY = selection.GetActivePointY(mePosLogical);
var line = Document.GetLine(Document.Selection.GetActivePointY(mePosLogical), 0);
var line = Document.GetLine(activeY);
var lineIndent = line.match(/^[ \t ]*/);
var lineIndent = line.match(/^[ \t ]*/);


selection.StartOfLine(false, mePosLogical);
selection.StartOfLine(false, mePosLogical);
if (insertIndent) {
if (insertIndent) {
   selection.Text = lineIndent;
   selection.Text = lineIndent + '\n';
} else {
  selection.Text = '\n';
}
}
var indentX = selection.GetActivePointX(mePosLogical);
selection.LineUp();
selection.Text = '\n';
selection.EndOfLine(false, mePosLogical);
selection.SetActivePoint(mePosLogical, indentX, ay);


Redraw = true;
Redraw = true;
 
</syntaxhighlight>
</source>

2025年6月30日 (月) 00:10時点における最新版

現在行の上に行挿入します。Shift + Enter や Ctrl + Shift + Enter に割り当てると便利です。

#title="上に行挿入"
Redraw = false;

// 以下の insertIndent のフラグを設定して、現在行のインデントを反映するかを選択してください。
// true: 現在行と同じインデントを挿入する
// false: 現在行のインデントを挿入しない
var insertIndent = true;

var selection = Document.Selection;
var activeY = selection.GetActivePointY(mePosLogical);
var line = Document.GetLine(activeY);
var lineIndent = line.match(/^[ \t ]*/);

selection.StartOfLine(false, mePosLogical);
if (insertIndent) {
  selection.Text = lineIndent + '\n';
} else {
  selection.Text = '\n';
}
selection.LineUp();
selection.EndOfLine(false, mePosLogical);

Redraw = true;
スポンサーリンク