Skip to content

Commit

Permalink
fixed markSelection and markExpand new command
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpoelen committed Jun 5, 2016
1 parent 1b40f18 commit 20f9c9d
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions commands/markSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,43 @@
* revision: 1
* kate-version: 4
* type: commands
* functions: markSelection, markJump, markClean
* functions: markSelection, markExpand, markJump, markClean
*/

require ("range.js");

var mark_on_selection = null;
var mark_on_selection2 = null;

function markSelection() {
var cursor = view.cursorPosition();
if (mark_on_selection && !cursor.equal(mark_on_selection)) {
if (mark_on_selection && !cursor.equals(mark_on_selection)) {
view.setSelection(new Range(cursor, mark_on_selection));
mark_on_selection2 = mark_on_selection;
mark_on_selection = null;
}
else {
mark_on_selection = cursor;
mark_on_selection2 = null;
}
}

function markExpand() {
var cursor = view.cursorPosition();
if (view.hasSelection()) {
var selection = view.selection();
if (selection.end.compareTo(cursor) >= 0 && selection.start.compareTo(cursor) > 0) {
view.setSelection(new Range(cursor, selection.end));
}
else {
view.setSelection(new Range(selection.start, cursor));
}
}
else {
mark_on_selection2 = mark_on_selection2 || mark_on_selection;
if (mark_on_selection2) {
view.setSelection(new Range(cursor, mark_on_selection2));
}
}
}

Expand All @@ -36,6 +58,9 @@ function help(cmd) {
if (cmd === 'markSelection') {
return i18n("Records the cursor position. The second call makes a selection.");
}
if (cmd === 'markExpand') {
return i18n("Extends selection or makes a selection from recorded cursor position.");
}
if (cmd === 'markJump') {
return i18n("Go to the recorded cursor position.");
}
Expand All @@ -53,4 +78,11 @@ function action(cmd)
text: i18n("Records position or makes a selection."),
shortcut: "Ctrl+3"
};
if ('markExpand' === cmd)
return {
category: "Selection",
interactive: false,
text: i18n("Extends selection or makes a selection from recorded position."),
shortcut: "Ctrl+4"
};
}

0 comments on commit 20f9c9d

Please sign in to comment.