Last active
February 7, 2017 15:56
-
-
Save s-hiiragi/efc06f04184d61ece1fe13e12204b323 to your computer and use it in GitHub Desktop.
選択範囲をレイアウト座標とロジック座標で相互変換するサクラエディタマクロのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @file sakura_selection_sample.js | |
* | |
* 注:Shift_JISで保存してください (サクラエディタマクロの制約事項) | |
*/ | |
/** | |
* 選択範囲(レイアウト座標) | |
* | |
* @param {number} lineFrom 選択開始行(レイアウト座標) | |
* @param {number} colmFrom 選択開始桁(レイアウト座標) | |
* @param {number} lineTo 選択終了行(レイアウト座標) | |
* @param {number} colmTo 選択終了桁(レイアウト座標) | |
*/ | |
function LayoutRange(lineFrom,colmFrom,lineTo,colmTo) { | |
this[0] = lineFrom; | |
this[1] = colmFrom; | |
this[2] = lineTo; | |
this[3] = colmTo; | |
this.length = 4; | |
} | |
LayoutRange.prototype = {}; | |
/** | |
* 選択範囲(ロジック座標)に変換 | |
* | |
* @return {LogicRange} 選択範囲(ロジック座標) | |
*/ | |
LayoutRange.prototype.toLogic = function() { | |
var r = [ | |
LayoutToLogicLineNum(this[0]), | |
LineColumnToIndex(this[0], this[1]), | |
LayoutToLogicLineNum(this[2]), | |
LineColumnToIndex(this[2], this[3]) | |
]; | |
return new LogicRange(r[0], r[1], r[2], r[3]); | |
}; | |
LayoutRange.prototype.toString = function() { | |
return '[' + this[0] + ',' + this[1] + ',' + this[2] + ',' + this[3] + ']'; | |
}; | |
/** | |
* 選択範囲(ロジック座標) | |
* | |
* @param {number} lineFrom 選択開始行(ロジック座標) | |
* @param {number} colmFrom 選択開始桁(ロジック座標) | |
* @param {number} lineTo 選択終了行(ロジック座標) | |
* @param {number} colmTo 選択終了桁(ロジック座標) | |
*/ | |
function LogicRange(lineFrom,colmFrom,lineTo,colmTo) { | |
this[0] = lineFrom; | |
this[1] = colmFrom; | |
this[2] = lineTo; | |
this[3] = colmTo; | |
this.length = 4; | |
} | |
LogicRange.prototype = {}; | |
/** | |
* 選択範囲(レイアウト座標)に変換 | |
* | |
* @return {LayoutRange} 選択範囲(レイアウト座標) | |
*/ | |
LogicRange.prototype.toLayout = function() { | |
var r = [ | |
LogicToLayoutLineNum(this[0], this[1]), | |
LineIndexToColumn(this[0], this[1]), | |
LogicToLayoutLineNum(this[2], this[3]), | |
LineIndexToColumn(this[2], this[3]) | |
]; | |
return new LayoutRange(r[0], r[1], r[2], r[3]); | |
}; | |
LogicRange.prototype.toString = function() { | |
return '[' + this[0] + ',' + this[1] + ',' + this[2] + ',' + this[3] + ']'; | |
}; | |
/** | |
* 現在の選択範囲(レイアウト座標)を取得 | |
* | |
* @return {LayoutRange} 選択範囲(レイアウト座標) | |
*/ | |
function GetSelection() { | |
return new LayoutRange( | |
Editor.GetSelectLineFrom(), | |
Editor.GetSelectColmFrom(), | |
Editor.GetSelectLineTo(), | |
Editor.GetSelectColmTo() | |
); | |
} | |
var layout = GetSelection(); | |
var Logic = layout.toLogic(); | |
var layout2 = Logic.toLayout(); | |
Editor.TraceOut(layout); | |
Editor.TraceOut(Logic); | |
Editor.TraceOut(layout2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment