[qwaq] Highlight the current line

This commit is contained in:
Bill Currie 2020-03-25 08:28:12 +09:00
parent 1c3e503ad2
commit 9a2ea54e78
4 changed files with 57 additions and 9 deletions

View file

@ -50,6 +50,7 @@
current_file = [self find_file: state.file];
file_proxy = [[ProxyView alloc] initWithView: current_file];
[[current_file gotoLine:state.line - 1] highlightLine];
//FIXME id<View>?
[source_window insertSelected: (View *) file_proxy];
[source_window setTitle: [current_file filename]];

View file

@ -496,7 +496,6 @@ formatLine (txtbuffer_t *buffer, unsigned linePtr, unsigned xpos,
while (c != '\n' && ptr < buffer->textSize) {
c = getChar (buffer, ptr++);
}
col = ptr >= sels && ptr < sele ? cols : coln;
while (length-- > 0) {
*dst++ = col | ' ';
}

View file

@ -13,9 +13,9 @@
eb_sel_t selection;
unsigned base_index; // top left corner
unsigned line_index; // current line
unsigned x_index; // horizontal scrolling
unsigned char_index; // current character
unsigned old_cind; // previous character
Point scroll;
Point cursor;
unsigned line_count;
string filename;
@ -26,6 +26,10 @@
-scrollDown:(unsigned) count;
-scrollLeft:(unsigned) count;
-scrollRight:(unsigned) count;
-recenter:(int) force;
-gotoLine:(unsigned) line;
-highlightLine;
@end
#endif//__qwaq_editor_h

View file

@ -29,7 +29,7 @@
unsigned lind = base_index;
int *lbuf = [linebuffer buffer];
for (int y = 0; y < ylen; y++) {
lind = [buffer formatLine:lind from:x_index into:lbuf width:xlen
lind = [buffer formatLine:lind from:scroll.x into:lbuf width:xlen
highlight:selection colors: {COLOR_PAIR (1), COLOR_PAIR(2)}];
[textContext blitFromBuffer: linebuffer to: {xpos, ypos + y}
from: [linebuffer rect]];
@ -99,10 +99,10 @@
-scrollLeft:(unsigned) count
{
if (x_index > count) {
x_index -= count;
if (scroll.x > count) {
scroll.x -= count;
} else {
x_index = 0;
scroll.x = 0;
}
[self redraw];
return self;
@ -110,13 +110,57 @@
-scrollRight:(unsigned) count
{
if (1024 - x_index > count) {
x_index += count;
if (1024 - scroll.x > count) {
scroll.x += count;
} else {
x_index = 1024;
scroll.x = 1024;
}
[self redraw];
return self;
}
-recenter:(int) force
{
if (!force) {
if (cursor.y >= scroll.y && cursor.y - scroll.y < ylen) {
return self;
}
}
unsigned target;
if (cursor.y < ylen / 2) {
target = 0;
} else {
target = cursor.y - ylen / 2;
}
if (target > scroll.y) {
base_index = [buffer nextLine:base_index :target - scroll.y];
} else if (target < scroll.y) {
base_index = [buffer prevLine:base_index :scroll.y - target];
}
scroll.y = target;
return self;
}
-gotoLine:(unsigned) line
{
if (line > cursor.y) {
line_index = [buffer nextLine:line_index :line - cursor.y];
} else if (line < cursor.y) {
line_index = [buffer prevLine:line_index :cursor.y - line];
}
cursor.y = line;
[self recenter: 0];
return self;
}
-highlightLine
{
selection.start = line_index;
selection.length = [buffer nextLine: line_index] - line_index;
if (!selection.length) {
selection.length = [buffer getEOL: line_index] - line_index;
}
return self;
}
@end