1
// This file is part of the Kate project within KDE.
2
// (C) 2009 Dominik Haumann <dhaumann kde org>
3
// License: LGPL v2 or v3
8
* \section cursor_intro Introduction
9
* The Cursor class provides the two properties \p line and \p column. Since a
10
* lot of text operations are based on lines and columns such as inserting text
11
* at a cursor position, the Cursor class plays a central role in KatePart
12
* scripting. The entire scripting API is usually based on cursors whenever
15
* \section cursor_usage Using Cursors
16
* There are several ways to construct a Cursor:
18
* var cursor1 = new Cursor(); // constructs a (valid) cursor at position (0, 0)
19
* var cursor2 = new Cursor(2, 4); // constructs a cursor at position (2, 4)
20
* var cursor3 = new Cursor(cursor2); // copies the cursor2
21
* var cursor4 = Cursor.invalid(); // constructs invalid cursor at (-1, -1)
24
* There are several convenience member functions that easy working with
25
* Cursors. Use isValid() to check whether a Cursor is a valid text cursor.
26
* To compare two cursors either use equals() or compareTo().
32
if (arguments.length === 0) {
33
return new Cursor(0, 0);
36
if (arguments.length === 1 && typeof arguments[0] == "object") {
37
// assume: cursor = new Cursor(otherCursor);
38
return arguments[0].clone();
41
if (arguments.length === 2 && typeof arguments[0] == "number"
42
&& typeof arguments[1] == "number") {
43
// assume: cursor = new Cursor(line, column);
44
this.line = parseInt(arguments[0], 10);
45
this.column = parseInt(arguments[1], 10);
47
throw "Wrong usage of Cursor constructor";
51
Cursor.prototype.clone = function() {
52
return new Cursor(this.line, this.column);
55
Cursor.prototype.setPosition = function(line, column) {
60
Cursor.prototype.isValid = function() {
61
return (this.line >= 0) && (this.column >= 0);
64
Cursor.prototype.compareTo = function(other) {
65
if (this.line > other.line || (this.line === other.line && this.column > other.column)) {
68
if (this.line < other.line || (this.line === other.line && this.column < other.column)) {
74
Cursor.prototype.equals = function(other) {
75
return (this.line === other.line && this.column === other.column);
78
Cursor.prototype.toString = function() {
80
return "Cursor(" + this.line+ "," + this.column+ ")";
86
Cursor.invalid = function() {
87
return new Cursor(-1, -1);
90
// kate: indent-width 2; replace-tabs on;