Menu ▾ ▴

#28 implement key_press_event and act on cursor-keys

open
nobody
None
2019-06-20
2019-06-20
Anonymous
No

Originally created by: douwevos

In the editor class connect a callback function to the key-press-event (https://github.com/douwevos/natpad/blob/4f394f08bcfdd40f7791775c62ea369bc03d6cc0/chameleon/src/chaeditor.c#L216). Note that key-events are not enabled by default in GDK (GDK is the layer beneath GTK) and you have to enable them by calling gtk_widget_set_events (https://github.com/douwevos/natpad/blob/4f394f08bcfdd40f7791775c62ea369bc03d6cc0/chameleon/src/chaeditor.c#L211)

The callback method should implement the GDK_KEY_Right, GDK_KEY_Left, GDK_KEY_Up and GDK_Down key-values (https://github.com/douwevos/natpad/blob/4f394f08bcfdd40f7791775c62ea369bc03d6cc0/chameleon/src/chaeditor.c#L727). A cursor move should move the cursor location, create a new TextModel version with the updated cursor location and post this new TextModel to the TextDocument. In theory this should already move the cursor visually on the screen.

As a bonus :) Think about the implications of an editor that is configured with a non-fixed-width font. What would the 'x' position (visually) of the cursor do when moving the cursor up or down. And what would it mean for the actual offset in a line. Even worse what would happen if I would move the cursor multiple lines up or down.

Related

Tickets: #30

Discussion


Log in to post a comment.