typedef struct {
void (*redraw)(int width, int height);
- void (*handle_key)(int mods, uint32_t rune);
+ void (*handle_key)(int mods, int32_t rune);
void (*shutdown)(void);
void (*set_focus)(bool focus);
void (*mouse_drag)(int state, int x, int y);
size_t rcount = 1;
syncgap(buf, off);
if (off < buf->outpoint) buf->outpoint++;
- if (rune == '\n') buf->nlines++;
+ if (rune == '\n' || rune == RUNE_CRLF) buf->nlines++;
if (buf->crlf && rune == '\n' && buf_get(buf, off-1) == '\r') {
rcount = 0;
*(buf->gapstart-1) = RUNE_CRLF;
void view_insert(View* view, bool indent, Rune rune) {
/* ignore non-printable control characters */
- if (!isspace(rune) && rune < 0x20)
+ if (!isspace(rune) && (rune >= 0 && rune < 0x20))
return;
if (num_selected(view->selection)) {
Sel sel = view->selection;
}
}
+ /* translate to crlf if needed */
+ if (key == '\n' && win_view(FOCUSED)->buffer.crlf)
+ key = RUNE_CRLF;
+
/* fallback to just inserting the rune if it doesn't fall in the private use area.
* the private use area is used to encode special keys */
if (key < 0xE000 || key > 0xF8FF) {
- if (InputFunc) {
+ if (InputFunc)
InputFunc(key);
- } else {
- if (key == '\n' && win_view(FOCUSED)->buffer.crlf)
- key = RUNE_CRLF;
+ else
view_insert(win_view(FOCUSED), true, key);
- }
}
}
#define EXPECT_EXIT \
if ((ExitExpected = true, 0 == setjmp(ExitPad)))
-
void setup_view(WinRegion id, char* text, int crlf, unsigned cursor) {
win_setregion(id);
win_buf(id)->crlf = crlf;
CHECK(win_sel(EDIT)->end == 1);
}
- TEST(input \n chould result in RUNE_CRLF if in crlf mode) {
+ TEST(input \n should result in RUNE_CRLF if in crlf mode) {
setup_view(EDIT, "", CRLF, 0);
win_buf(EDIT)->crlf = 1;
send_keys(ModNone, XK_Return);
CHECK(win_sel(EDIT)->end == 1);
CHECK('\n' == buf_get(win_buf(EDIT), 0));
}
-
/* Key Handling - Cursor Movement - Basic
*************************************************************************/
TEST(left should do nothing for empty buffer) {
if (win_getregion() == EDIT) {
size_t point = win_buf(EDIT)->outpoint;
size_t pos = win_view(EDIT)->selection.end;
- if (rune == '\n' && pos > point) {
+ if ((rune == '\n' || rune == RUNE_CRLF) && pos > point) {
Sel range = { .beg = point, .end = pos };
char* str = view_getstr(win_view(EDIT), &range);
if (write(CmdFD, str, strlen(str)-1) < 0)