0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
| |
function getOpenMode(){
return Editor.ExpandParameter("${R?r$:$:$}");
}
function getCursorLogicCoordinates() {
var cursorLine = ExpandParameter('$y') - 0;
var cursorColumn = ExpandParameter('$x') - 0;
return [cursorLine, cursorColumn];
}
function getSelectLogicCoordinatesFrom() {
var layoutSelectLineFrom = GetSelectLineFrom();
var selectLineFrom = LayoutToLogicLineNum(layoutSelectLineFrom);
var selectColumnFrom = LineColumnToIndex(layoutSelectLineFrom, GetSelectColumnFrom());
return [selectLineFrom, selectColumnFrom];
}
function getSelectLogicCoordinatesTo() {
var layoutSelectLineTo = GetSelectLineTo();
var selectLineTo = LayoutToLogicLineNum(layoutSelectLineTo);
var selectColumnTo = LineColumnToIndex(layoutSelectLineTo, GetSelectColumnTo());
return [selectLineTo, selectColumnTo];
}
function isEqualArray(array1, array2) {
var i = array1.length;
if (i != array2.length) return false;
while (i--) {
if (array1[i] !== array2[i]) return false;
}
return true;
};
function keepSelect(cursor, selectFrom, selectTo) {
if (isEqualArray(cursor, selectFrom)) {
MoveCursor(selectTo[0], selectTo[1], 0);
} else {
MoveCursor(selectFrom[0], selectFrom[1], 0);
}
MoveCursor(cursor[0], cursor[1], 1);
}
function getLastLine() {
goFileEnd();
return ExpandParameter('$y') - 0;
}
function isLastLine(line) {
return line == getLineCount(0) + 1;
}
function copyLineUp(){
if (getOpenMode() == "r") return;
var cursor = getCursorLogicCoordinates();
var txt = "";
CommitUndoBuffer(); AddRefUndoBuffer(); AppendUndoBufferCursor(); SetDrawSwitch(0);
if (isTextSelected()) {
var selectFrom = getSelectLogicCoordinatesFrom();
var selectTo = getSelectLogicCoordinatesTo();
var len = selectTo[0] - selectFrom[0] + 1;
for (var i = 0; i < len; i++) { txt += GetLineStr(selectFrom[0] + i); }
var lastLine = getLastLine();
MoveCursor(selectFrom[0], 1, 0);
InsText(txt);
if (lastLine == selectTo[0]) char(13);
keepSelect(cursor, selectFrom, selectTo);
} else {
txt += GetLineStr(cursor[0]);
var lastLine = getLastLine();
MoveCursor(cursor[0], 1, 0);
InsText(txt);
if (lastLine == cursor[0]) char(13);
MoveCursor(cursor[0], cursor[1], 0);
}
SetUndoBuffer(); SetDrawSwitch(1); ReDraw();
}
copyLineUp();
|