mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
[qwaq] Extract the double-clicked word
The plan is to use it for variable lookups etc.
This commit is contained in:
parent
585b33c111
commit
7b9177ec56
6 changed files with 84 additions and 11 deletions
|
@ -79,8 +79,12 @@
|
|||
|
||||
-(void)key_event: (ed_event_t *)_event
|
||||
{
|
||||
Editor *file = _event.editor;
|
||||
qwaq_event_t *event = _event.event;
|
||||
if (event.what == qe_keydown) {
|
||||
if (event.what == qe_mouseclick) {
|
||||
printf ("%s\n", [file getWordAt: {event.mouse.x, event.mouse.y}]);
|
||||
[source_window redraw];
|
||||
} else if (event.what == qe_keydown) {
|
||||
switch (event.key.code) {
|
||||
case QFK_F7:
|
||||
qdb_set_trace (debug_target, 1);
|
||||
|
|
|
@ -277,6 +277,25 @@ getEOL (txtbuffer_t *buffer, unsigned ptr)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
static always_inline void
|
||||
readString (txtbuffer_t *buffer, eb_sel_t *sel, char *str)
|
||||
{
|
||||
unsigned start = sel->start;
|
||||
unsigned length = sel->length;
|
||||
unsigned end = sel->start + sel->length;
|
||||
const char *ptr = buffer->text + spanGap (buffer, start);
|
||||
if ((start < buffer->gapOffset && end <= buffer->gapOffset)
|
||||
|| start > buffer->gapOffset) {
|
||||
memcpy (str, ptr, length);
|
||||
} else {
|
||||
length = buffer->gapOffset - start;
|
||||
memcpy (str, ptr, length);
|
||||
str += length;
|
||||
ptr += length + buffer->gapOffset;
|
||||
memcpy (str, ptr, sel->length - length);
|
||||
}
|
||||
}
|
||||
|
||||
static always_inline unsigned
|
||||
getBOL (txtbuffer_t *buffer, unsigned ptr)
|
||||
{
|
||||
|
@ -773,6 +792,21 @@ bi_i_EditBuffer__getEOT (progs_t *pr)
|
|||
R_INT (pr) = buffer->txtbuffer->textSize;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_i_EditBuffer__readString_ (progs_t *pr)
|
||||
{
|
||||
qwaq_ebresources_t *res = PR_Resources_Find (pr, "qwaq-editbuffer");
|
||||
int buffer_id = P_STRUCT (pr, qwaq_editbuffer_t, 0).buffer;
|
||||
editbuffer_t *buffer = get_editbuffer (res, __FUNCTION__, buffer_id);
|
||||
__auto_type selection = &P_PACKED (pr, eb_sel_t, 2);
|
||||
|
||||
char *str = alloca (selection->length + 1);
|
||||
str[selection->length] = 0;
|
||||
readString (buffer->txtbuffer, selection, str);
|
||||
|
||||
RETURN_STRING (pr, str);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_i_EditBuffer__countLines_ (progs_t *pr)
|
||||
{
|
||||
|
@ -901,6 +935,7 @@ static builtin_t builtins[] = {
|
|||
{"_i_EditBuffer__getEOL_", bi_i_EditBuffer__getEOL_, -1},
|
||||
{"_i_EditBuffer__getBOT", bi_i_EditBuffer__getBOT, -1},
|
||||
{"_i_EditBuffer__getEOT", bi_i_EditBuffer__getEOT, -1},
|
||||
{"_i_EditBuffer__readString_", bi_i_EditBuffer__readString_, -1},
|
||||
{"_i_EditBuffer__countLines_", bi_i_EditBuffer__countLines_, -1},
|
||||
{"_i_EditBuffer__search_for_direction_",
|
||||
bi_i_EditBuffer__search_for_direction_, -1},
|
||||
|
|
|
@ -49,6 +49,7 @@ typedef struct eb_color_s {
|
|||
- (unsigned) getEOL: (unsigned) linePtr;
|
||||
- (unsigned) getBOT;
|
||||
- (unsigned) getEOT;
|
||||
- (string) readString: (eb_sel_t) selection;
|
||||
|
||||
- (unsigned) countLines: (eb_sel_t) selection;
|
||||
- (eb_sel_t) search: (eb_sel_t) selection
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
- (unsigned) getEOL: (unsigned) linePtr = #0;
|
||||
- (unsigned) getBOT = #0;
|
||||
- (unsigned) getEOT = #0;
|
||||
- (string) readString: (eb_sel_t) selection = #0;
|
||||
|
||||
- (unsigned) countLines: (eb_sel_t) selection = #0;
|
||||
- (eb_sel_t) search: (eb_sel_t) selection
|
||||
|
|
|
@ -41,6 +41,7 @@ typedef struct ed_event_s {
|
|||
-recenter:(int) force;
|
||||
-gotoLine:(unsigned) line;
|
||||
-highlightLine;
|
||||
-(string)getWordAt:(Point) pos; // view relative coordinates
|
||||
@end
|
||||
|
||||
#endif//__qwaq_editor_h
|
||||
|
|
|
@ -51,38 +51,57 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
-handleEvent:(qwaq_event_t *) event
|
||||
static int handleEvent (Editor *self, qwaq_event_t *event)
|
||||
{
|
||||
// give any listeners a chance to override or extend event handling
|
||||
_event.editor = self;
|
||||
_event.event = event;
|
||||
[onEvent respond: &_event];
|
||||
if (event.what & qe_mouse) {
|
||||
if (event.what == qe_mouseclick) {
|
||||
if (event.mouse.buttons & (1 << 3)) {
|
||||
[self scrollUp: 1];
|
||||
return 1;
|
||||
}
|
||||
if (event.mouse.buttons & (1 << 4)) {
|
||||
[self scrollDown: 1];
|
||||
return 1;
|
||||
}
|
||||
if (event.mouse.buttons & (1 << 5)) {
|
||||
[self scrollLeft: 1];
|
||||
return 1;
|
||||
}
|
||||
if (event.mouse.buttons & (1 << 6)) {
|
||||
[self scrollRight: 1];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} else if (event.what == qe_keydown) {
|
||||
switch (event.key.code) {
|
||||
case QFK_PAGEUP:
|
||||
[self scrollUp: ylen];
|
||||
break;
|
||||
[self scrollUp: self.ylen];
|
||||
return 1;
|
||||
case QFK_PAGEDOWN:
|
||||
[self scrollDown: ylen];
|
||||
break;
|
||||
[self scrollDown: self.ylen];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
-handleEvent:(qwaq_event_t *) event
|
||||
{
|
||||
// give any listeners a chance to override or extend event handling
|
||||
_event.editor = self;
|
||||
_event.event = event;
|
||||
if (event.what & qe_positional) {
|
||||
event.mouse.x -= xpos;
|
||||
event.mouse.y -= ypos;
|
||||
}
|
||||
[onEvent respond: &_event];
|
||||
if (handleEvent (self, event)) {
|
||||
event.what = qe_none;
|
||||
}
|
||||
if (event.what & qe_positional) {
|
||||
event.mouse.x += xpos;
|
||||
event.mouse.y += ypos;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -174,4 +193,16 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
-(string)getWordAt:(Point) pos
|
||||
{
|
||||
if (pos.x < 0 || pos.y < 0 || pos.x >= xlen || pos.y >= ylen) {
|
||||
return nil;
|
||||
}
|
||||
pos.x += scroll.x;
|
||||
unsigned lind = [buffer nextLine:base_index :pos.y];
|
||||
unsigned cind = [buffer charPtr:lind at:pos.x];
|
||||
eb_sel_t word = [buffer getWord: cind];
|
||||
return [buffer readString:word];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue