[code] [textadept] Sync Curses Cursor for tmux Copy Mode

From: <cavoegele.att.gmail.com>
Date: Sun, 13 Aug 2017 16:11:42 -0700

Hi Textadept Users!

One bit of functionality I miss from Vim is the seamless transition from
Vim to tmux copy mode. The tmux cursor starts at the current position of
the Vim cursor. In textadept-curses, the tmux cursor always starts at
the bottom-left corner of the screen.

I dug into this issue a bit and it's caused by Scintilla drawing the
caret as a single, inverted-color character and hiding the terminal
cursor. Tmux copy mode starts from the position of the terminal cursor.
A workaround in the patch below is to move the terminal cursor to the
current position of the Scintilla caret after painting is finished. This
works for screen and tmux including for split views. However it doesn't
work for the command entry cursor.

Any chance we can get this patch cleaned up and merged upstream?

Thank you Mitchell for textadept! I'll never have to see vimscript
again!

Here are the modules I have been working on if anyone is interested:
- textadept-vi (https://github.com/chadvoegele/textadept-vi)
- textadept-slime (https://github.com/chadvoegele/textadept-slime)
- textadept-js (https://github.com/chadvoegele/textadept-js)

And some native curses build instructions for MacOS:
- textadept-mac (https://github.com/chadvoegele/textadept-mac)

Cheers,
Chad

# HG changeset patch
# User Chad Voegele <cavoegele.att.gmail.com>
# Date 1502658623 25200
# Sun Aug 13 14:10:23 2017 -0700
# Branch sync_curses_cursor
# Node ID 6f9214c010410b9da1fd4c9ec06e54b853647549
# Parent 81a105a503158e65ebd40296749877d3a39103d0
Move curses cursor to current_pos after painting.

diff -r 81a105a50315 -r 6f9214c01041 src/textadept.c
--- a/src/textadept.c Tue Jul 25 09:52:28 2017 -0400
+++ b/src/textadept.c Sun Aug 13 14:10:23 2017 -0700
@@ -1926,6 +1926,17 @@
   lL_event(L, "SCN", LUA_TTABLE, luaL_ref(L, LUA_REGISTRYINDEX), -1);
 }
 
+static void curses_cursor_to_current_pos(Scintilla *view) {
+#if CURSES
+ int current_pos = SS(view, SCI_GETCURRENTPOS, 0, 0);
+ int pointx = SS(view, SCI_POINTXFROMPOSITION, 0, current_pos);
+ int pointy = SS(view, SCI_POINTYFROMPOSITION, 0, current_pos);
+ int begy, begx;
+ getbegyx(scintilla_get_window(view), begy, begx);
+ move(pointy + begy, pointx + begx);
+#endif
+}
+
 /** Signal for a Scintilla notification. */
 static void s_notify(Scintilla *view, int _, void *lParam, void*__) {
   struct SCNotification *n = (struct SCNotification *)lParam;
@@ -1938,6 +1949,9 @@
     goto_view(view), lL_notify(lua, n), goto_view(prev);
   } else if (n->nmhdr.code == SCN_FOCUSIN)
     goto_view(view);
+ if (n->nmhdr.code == SCN_PAINTED) {
+ curses_cursor_to_current_pos(focused_view); // for tmux/screen copy mode
+ }
 }
 
 #if GTK

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Sun 13 Aug 2017 - 19:11:42 EDT

This archive was generated by hypermail 2.2.0 : Mon 14 Aug 2017 - 06:36:16 EDT