diff options
author | Jesper K. Pedersen <jesper.pedersen@kdab.com> | 2013-04-18 07:56:34 +0200 |
---|---|---|
committer | Jesper K. Pedersen <jesper.pedersen@kdab.com> | 2013-04-18 11:44:48 +0200 |
commit | b41e8b4ba6dde7824dd5b637c7ceb81920f54a7b (patch) | |
tree | 4f590f38fe0d0d4ef2ad65964797c1b0d3f9b1e5 | |
parent | 6c28191412ad2b7a7ebc50a808bb7c0f162466ff (diff) |
started an examples subdirectory of useful scripts
Change-Id: Ie2db7a8a45fa09d7b41ce93ff09dce8c5bd15374
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
-rw-r--r-- | examples/string-rectangle.qs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/string-rectangle.qs b/examples/string-rectangle.qs new file mode 100644 index 0000000..50c689f --- /dev/null +++ b/examples/string-rectangle.qs @@ -0,0 +1,37 @@ +// This script is similar to emacs' string-rectangle. +// As an example, select three lines of "var" below, run the script, +// and type "Variable", and see how the "var"'s are replaced with "Variable" + +var text = dialogs.getText("Rectangular Insert", "String to insert") +var editor = editors.current() + +var anchorPos = editor.position(PositionOperation.Anchor) +var anchorColumn = editor.convertPosition(anchorPos).x +var anchorLine = editor.convertPosition(anchorPos).y + +var pointPos = editor.position(PositionOperation.Current) +var pointColumn = editor.convertPosition(pointPos).x +var pointLine = editor.convertPosition(pointPos).y + +var startColumn, endColumn, startLine, endLine +if ( anchorLine < pointLine || (anchorLine == pointLine && anchorColumn < pointColumn)) { + startColumn = anchorColumn + endColumn = pointColumn + startLine = anchorLine + endLine = pointLine +} +else { + startColumn = pointColumn + endColumn = anchorColumn + startLine = pointLine + endLine = anchorLine +} + +if ( startLine != -1 || startColumn != -1) { + var line = startLine + while ( line <= endLine ) { + editor.gotoLine(line,startColumn) + editor.replace(endColumn-startColumn, text) + line = line +1 + } +} |