summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/kill-rectangle.qs4
-rw-r--r--examples/open-rectangle.qs4
-rw-r--r--examples/rectangle-commands.js55
-rw-r--r--examples/string-rectangle.qs35
4 files changed, 65 insertions, 33 deletions
diff --git a/examples/kill-rectangle.qs b/examples/kill-rectangle.qs
new file mode 100644
index 0000000..0b94409
--- /dev/null
+++ b/examples/kill-rectangle.qs
@@ -0,0 +1,4 @@
+// This script is similar to emacs' kill-rectangle.
+
+include("rectangle-commands.js")
+replaceTextInRectangle("")
diff --git a/examples/open-rectangle.qs b/examples/open-rectangle.qs
new file mode 100644
index 0000000..06b06cb
--- /dev/null
+++ b/examples/open-rectangle.qs
@@ -0,0 +1,4 @@
+// This script is similar to emacs' open-rectangle.
+
+include("rectangle-commands.js")
+openRectangle()
diff --git a/examples/rectangle-commands.js b/examples/rectangle-commands.js
new file mode 100644
index 0000000..5e620d8
--- /dev/null
+++ b/examples/rectangle-commands.js
@@ -0,0 +1,55 @@
+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
+}
+
+
+function replaceTextInRectangle(text) {
+ if ( startLine != -1 || startColumn != -1) {
+ var line = startLine
+ while ( line <= endLine ) {
+ editor.gotoLine(line,startColumn)
+ editor.replace(endColumn-startColumn, text)
+ line = line +1
+ }
+ }
+}
+
+function spaces(count) {
+ var result = ""
+ for (var i=0; i < count; i++) {
+ result = result + " "
+ }
+ return result
+}
+
+function openRectangle() {
+ if ( startLine != -1 || startColumn != -1) {
+ var line = startLine
+ while ( line <= endLine ) {
+ editor.gotoLine(line,startColumn)
+ editor.replace(0, spaces(endColumn-startColumn))
+ line = line +1
+ }
+
+ }
+}
diff --git a/examples/string-rectangle.qs b/examples/string-rectangle.qs
index 50c689f..f47f566 100644
--- a/examples/string-rectangle.qs
+++ b/examples/string-rectangle.qs
@@ -1,37 +1,6 @@
// 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"
+include("rectangle-commands.js")
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
- }
-}
+replaceTextInRectangle(text)