move to first non-whitespace on next line
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
|
|||||||
project(ke C) # Specify C language explicitly
|
project(ke C) # Specify C language explicitly
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(KE_VERSION "1.3.3")
|
set(KE_VERSION "1.3.4")
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g")
|
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
}:
|
}:
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
pname = "ke";
|
pname = "ke";
|
||||||
version = "1.3.3";
|
version = "1.3.4";
|
||||||
|
|
||||||
src = lib.cleanSource ./.;
|
src = lib.cleanSource ./.;
|
||||||
|
|
||||||
|
|||||||
49
main.c
49
main.c
@@ -21,6 +21,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
#include <wctype.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -1589,6 +1590,41 @@ editor_openfile(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
first_nonwhitespace(struct erow *row)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
wchar_t wc;
|
||||||
|
mbstate_t state;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (row == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&state, 0, sizeof(state));
|
||||||
|
pos = 0;
|
||||||
|
while (pos < row->size) {
|
||||||
|
len = mbrtowc(&wc, &row->line[pos], row->size - pos, &state);
|
||||||
|
if (len == (size_t) -1 || len == (size_t) -2) {
|
||||||
|
/* Invalid or incomplete sequence, stop here */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (len == 0) {
|
||||||
|
/* Null character, stop here */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!iswspace(wc)) {
|
||||||
|
/* Found non-whitespace character */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pos += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
move_cursor(int16_t c)
|
move_cursor(int16_t c)
|
||||||
{
|
{
|
||||||
@@ -1602,12 +1638,20 @@ move_cursor(int16_t c)
|
|||||||
case CTRL_KEY('p'):
|
case CTRL_KEY('p'):
|
||||||
if (editor.cury > 0) {
|
if (editor.cury > 0) {
|
||||||
editor.cury--;
|
editor.cury--;
|
||||||
|
row = (editor.cury >= editor.nrows)
|
||||||
|
? NULL
|
||||||
|
: &editor.row[editor.cury];
|
||||||
|
editor.curx = first_nonwhitespace(row);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ARROW_DOWN:
|
case ARROW_DOWN:
|
||||||
case CTRL_KEY('n'):
|
case CTRL_KEY('n'):
|
||||||
if (editor.cury < editor.nrows) {
|
if (editor.cury < editor.nrows) {
|
||||||
editor.cury++;
|
editor.cury++;
|
||||||
|
row = (editor.cury >= editor.nrows)
|
||||||
|
? NULL
|
||||||
|
: &editor.row[editor.cury];
|
||||||
|
editor.curx = first_nonwhitespace(row);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ARROW_RIGHT:
|
case ARROW_RIGHT:
|
||||||
@@ -1622,7 +1666,10 @@ move_cursor(int16_t c)
|
|||||||
}
|
}
|
||||||
} else if (row && editor.curx == row->size) {
|
} else if (row && editor.curx == row->size) {
|
||||||
editor.cury++;
|
editor.cury++;
|
||||||
editor.curx = 0;
|
row = (editor.cury >= editor.nrows)
|
||||||
|
? NULL
|
||||||
|
: &editor.row[editor.cury];
|
||||||
|
editor.curx = first_nonwhitespace(row);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ARROW_LEFT:
|
case ARROW_LEFT:
|
||||||
|
|||||||
Reference in New Issue
Block a user