mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
Start selection box
This commit is contained in:
@@ -4,6 +4,9 @@ class Cursor {
|
|||||||
int x, y;
|
int x, y;
|
||||||
int lastX;
|
int lastX;
|
||||||
|
|
||||||
|
uint selectionStart;
|
||||||
|
uint selectionEnd;
|
||||||
|
|
||||||
this() {}
|
this() {}
|
||||||
|
|
||||||
this(int x, int y) {
|
this(int x, int y) {
|
||||||
|
|||||||
24
src/view.d
24
src/view.d
@@ -144,6 +144,21 @@ class View {
|
|||||||
}
|
}
|
||||||
cursor.x = getCharPosition(cursor.y, e.x - xOffset);
|
cursor.x = getCharPosition(cursor.y, e.x - xOffset);
|
||||||
cursor.lastX = cursor.x;
|
cursor.lastX = cursor.x;
|
||||||
|
|
||||||
|
cursor.selectionStart = 0;
|
||||||
|
cursor.selectionEnd = 0;
|
||||||
|
} else if (e.key == Key.mouseRelease) {
|
||||||
|
auto y = e.y + topline;
|
||||||
|
if (y - topline > height-1) {
|
||||||
|
y = height + topline-1;
|
||||||
|
}
|
||||||
|
if (y > buf.lines.length) {
|
||||||
|
y = cast(int) buf.lines.length-1;
|
||||||
|
}
|
||||||
|
auto x = getCharPosition(y, e.x - xOffset);
|
||||||
|
|
||||||
|
cursor.selectionStart = toCharNumber(cursor.x, cursor.y);
|
||||||
|
cursor.selectionEnd = toCharNumber(x, y);
|
||||||
} else if (e.key == Key.ctrlS) {
|
} else if (e.key == Key.ctrlS) {
|
||||||
if (buf.path != "") {
|
if (buf.path != "") {
|
||||||
buf.save();
|
buf.save();
|
||||||
@@ -200,6 +215,7 @@ class View {
|
|||||||
ulong maxLength = to!string(buf.lines.length).length;
|
ulong maxLength = to!string(buf.lines.length).length;
|
||||||
xOffset = cast(int) maxLength + 1;
|
xOffset = cast(int) maxLength + 1;
|
||||||
|
|
||||||
|
int chNum;
|
||||||
foreach (i, line; lines) {
|
foreach (i, line; lines) {
|
||||||
// Write the line number
|
// Write the line number
|
||||||
string lineNum = to!string(i + topline + 1);
|
string lineNum = to!string(i + topline + 1);
|
||||||
@@ -213,10 +229,16 @@ class View {
|
|||||||
|
|
||||||
// Write the line
|
// Write the line
|
||||||
foreach (dchar ch; line.replaceAll(regex("\t"), emptyString(tabSize))) {
|
foreach (dchar ch; line.replaceAll(regex("\t"), emptyString(tabSize))) {
|
||||||
setCell(x++, y, ch, Color.basic, Color.basic);
|
auto color = Color.basic;
|
||||||
|
if (chNum > cursor.selectionStart && chNum < cursor.selectionEnd) {
|
||||||
|
color = cast(Color) (Color.basic | Attribute.reverse);
|
||||||
|
}
|
||||||
|
setCell(x++, y, ch, color, color);
|
||||||
|
chNum++;
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
x = 0;
|
x = 0;
|
||||||
|
chNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor.y - topline < 0 || cursor.y - topline > height-1) {
|
if (cursor.y - topline < 0 || cursor.y - topline > height-1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user