mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[qwaq] Implement cursor motion in the editor
Basic arrow key motion, and it's currently limited to not scrolling horizontally (need to figure out how to handle max scroll), but this also fixes the cursor handling on focus switching :)
This commit is contained in:
parent
551236511d
commit
1f6a4ed941
3 changed files with 76 additions and 1 deletions
|
@ -28,6 +28,10 @@
|
||||||
-scrollDown:(unsigned) count;
|
-scrollDown:(unsigned) count;
|
||||||
-scrollLeft:(unsigned) count;
|
-scrollLeft:(unsigned) count;
|
||||||
-scrollRight:(unsigned) count;
|
-scrollRight:(unsigned) count;
|
||||||
|
-cursorUp:(unsigned) count;
|
||||||
|
-cursorDown:(unsigned) count;
|
||||||
|
-cursorLeft:(unsigned) count;
|
||||||
|
-cursorRight:(unsigned) count;
|
||||||
|
|
||||||
-recenter:(int) force;
|
-recenter:(int) force;
|
||||||
-gotoLine:(unsigned) line;
|
-gotoLine:(unsigned) line;
|
||||||
|
|
|
@ -94,6 +94,18 @@ handleEvent (Editor *self, qwaq_event_t *event)
|
||||||
case QFK_PAGEDOWN:
|
case QFK_PAGEDOWN:
|
||||||
[self scrollDown: self.ylen];
|
[self scrollDown: self.ylen];
|
||||||
return 1;
|
return 1;
|
||||||
|
case QFK_UP:
|
||||||
|
[self cursorUp: 1];
|
||||||
|
return 1;
|
||||||
|
case QFK_DOWN:
|
||||||
|
[self cursorDown: 1];
|
||||||
|
return 1;
|
||||||
|
case QFK_LEFT:
|
||||||
|
[self cursorLeft: 1];
|
||||||
|
return 1;
|
||||||
|
case QFK_RIGHT:
|
||||||
|
[self cursorRight: 1];
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -139,6 +151,7 @@ handleEvent (Editor *self, qwaq_event_t *event)
|
||||||
base.x = 0;
|
base.x = 0;
|
||||||
}
|
}
|
||||||
[self redraw];
|
[self redraw];
|
||||||
|
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +163,7 @@ handleEvent (Editor *self, qwaq_event_t *event)
|
||||||
base.x = 1024;
|
base.x = 1024;
|
||||||
}
|
}
|
||||||
[self redraw];
|
[self redraw];
|
||||||
|
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +175,60 @@ handleEvent (Editor *self, qwaq_event_t *event)
|
||||||
base_index = [buffer prevLine:base_index :base.y - target];
|
base_index = [buffer prevLine:base_index :base.y - target];
|
||||||
}
|
}
|
||||||
base.y = target;
|
base.y = target;
|
||||||
|
[vScrollBar setIndex:base.y];
|
||||||
|
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
-cursorUp:(unsigned)count
|
||||||
|
{
|
||||||
|
if (count > cursor.y) {
|
||||||
|
count = cursor.y;
|
||||||
|
}
|
||||||
|
cursor.y -= count;
|
||||||
|
if (base.y > cursor.y) {
|
||||||
|
[vScrollBar setIndex:cursor.y];
|
||||||
|
}
|
||||||
|
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
-cursorDown:(unsigned)count
|
||||||
|
{
|
||||||
|
if (count > line_count - cursor.y) {
|
||||||
|
count = line_count - cursor.y;
|
||||||
|
}
|
||||||
|
cursor.y += count;
|
||||||
|
if (base.y + ylen - 1 < cursor.y) {
|
||||||
|
[vScrollBar setIndex:cursor.y + 1 - ylen];
|
||||||
|
}
|
||||||
|
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
-cursorLeft:(unsigned)count
|
||||||
|
{
|
||||||
|
if (count > cursor.x) {
|
||||||
|
count = cursor.x;
|
||||||
|
}
|
||||||
|
cursor.x -= count;
|
||||||
|
if (base.x > cursor.x) {
|
||||||
|
[hScrollBar setIndex:cursor.x];
|
||||||
|
}
|
||||||
|
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
-cursorRight:(unsigned)count
|
||||||
|
{
|
||||||
|
// FIXME handle horizontal scrolling and how to deal with max scroll
|
||||||
|
cursor.x += count;
|
||||||
|
if (base.x + xlen - 1 < cursor.x) {
|
||||||
|
[hScrollBar setIndex:cursor.x + 1 - xlen];
|
||||||
|
}
|
||||||
|
if (base.x + xlen - 1 < cursor.x) {
|
||||||
|
cursor.x = base.x + xlen - 1;
|
||||||
|
}
|
||||||
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +236,9 @@ handleEvent (Editor *self, qwaq_event_t *event)
|
||||||
-(void)onScroll:(id)sender
|
-(void)onScroll:(id)sender
|
||||||
{
|
{
|
||||||
base.x = scroll.x;
|
base.x = scroll.x;
|
||||||
[self scrollTo:scroll.y];
|
if (base.y != scroll.y) {
|
||||||
|
[self scrollTo:scroll.y];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-setVerticalScrollBar:(ScrollBar *)scrollbar
|
-setVerticalScrollBar:(ScrollBar *)scrollbar
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
window_t window = [(id)textContext window];
|
window_t window = [(id)textContext window];
|
||||||
curs_set (cursorState);
|
curs_set (cursorState);
|
||||||
wmove (window, cursorPos.x, cursorPos.y);
|
wmove (window, cursorPos.x, cursorPos.y);
|
||||||
|
[[TextContext screen] refresh];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue