diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-04-16 11:50:17 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-16 12:52:04 +0200 |
| commit | 2499521dc70b064007df652af8e68eaad8acbf2b (patch) | |
| tree | d2f504bfa0adbf5a7c3ca96901f025aada5e35ad | |
| parent | b02c26e64aca90c3d2f3af0e94a985dc43831655 (diff) | |
| download | vis-2499521dc70b064007df652af8e68eaad8acbf2b.tar.gz vis-2499521dc70b064007df652af8e68eaad8acbf2b.tar.xz | |
vis-lua: add cursor.selection property
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | vis-lua.c | 16 |
2 files changed, 17 insertions, 0 deletions
@@ -605,6 +605,7 @@ At this time there exists no API stability guarantees. - `to(line, col)` - `pos` bytes from start of file (0 based) - `number` zero based index of cursor + - `selection` either `nil` or a table `{start, finish}` Most of the exposed objects are managed by the C core. Allthough there is a simple object life time management mechanism in place, it is still @@ -645,6 +645,22 @@ static int window_cursor_index(lua_State *L) { lua_pushunsigned(L, view_cursors_number(cur)+1); return 1; } + + if (strcmp(key, "selection") == 0) { + Filerange sel = view_cursors_selection_get(cur); + if (text_range_valid(&sel)) { + lua_createtable(L, 0, 2); + lua_pushstring(L, "start"); + lua_pushunsigned(L, sel.start); + lua_settable(L, -3); + lua_pushstring(L, "finish"); + lua_pushunsigned(L, sel.end); + lua_settable(L, -3); + } else { + lua_pushnil(L); + } + return 1; + } } return index_common(L); |
