~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to part/script/data/libraries/cursor.js

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
 
 
5
 
/**
6
 
 * Prototype Cursor.
7
 
 *
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
13
 
 * possible.
14
 
 *
15
 
 * \section cursor_usage Using Cursors
16
 
 * There are several ways to construct a Cursor:
17
 
 * \code
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)
22
 
 * \endcode
23
 
 *
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().
27
 
 *
28
 
 * \see Range
29
 
 */
30
 
function Cursor() {
31
 
 
32
 
  if (arguments.length === 0) {
33
 
    return new Cursor(0, 0);
34
 
  }
35
 
 
36
 
  if (arguments.length === 1 && typeof arguments[0] == "object") {
37
 
    // assume: cursor = new Cursor(otherCursor);
38
 
    return arguments[0].clone();
39
 
  }
40
 
 
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);
46
 
  } else {
47
 
    throw "Wrong usage of Cursor constructor";
48
 
  }
49
 
}
50
 
 
51
 
Cursor.prototype.clone = function() {
52
 
  return new Cursor(this.line, this.column);
53
 
}
54
 
 
55
 
Cursor.prototype.setPosition = function(line, column) {
56
 
  this.line = line;
57
 
  this.column = column;
58
 
}
59
 
 
60
 
Cursor.prototype.isValid = function() {
61
 
  return (this.line >= 0) && (this.column >= 0);
62
 
}
63
 
 
64
 
Cursor.prototype.compareTo = function(other) {
65
 
  if (this.line > other.line || (this.line === other.line && this.column > other.column)) {
66
 
    return 1;
67
 
  }
68
 
  if (this.line < other.line || (this.line === other.line && this.column < other.column)) {
69
 
    return -1;
70
 
  }
71
 
  return 0;
72
 
}
73
 
 
74
 
Cursor.prototype.equals = function(other) {
75
 
  return (this.line === other.line && this.column === other.column);
76
 
}
77
 
 
78
 
Cursor.prototype.toString = function() {
79
 
  if (this.isValid()) {
80
 
    return "Cursor(" + this.line+ "," + this.column+ ")";
81
 
  } else {
82
 
    return "Cursor()";
83
 
  }
84
 
}
85
 
 
86
 
Cursor.invalid = function() {
87
 
  return new Cursor(-1, -1);
88
 
}
89
 
 
90
 
// kate: indent-width 2; replace-tabs on;