Clone in a terminal:
Commit 43999e1
Johan Mattsson - 2019-07-19T17:50:36+00:00
43999e1ba2923792449ad1ecdd0ec2eb7b1fb5fcjohan.mattsson.m@gmail.com

Support for double clicks in text area (select one word)

Changed files (4)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex ffeb03c..31437bb 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -689,9 +689,7 @@ public class GlyphCanvasArea : DrawingArea  { 		event_flags |= EventMask.SCROLL_MASK; 		 		add_events (event_flags);--		bool button_down = false;-+		 		glyph_canvas.signal_redraw_area.connect ((x, y, w, h) => { 			queue_draw_area ((int)x, (int)y, (int)w, (int)h); 		});@@ -725,10 +723,6 @@ public class GlyphCanvasArea : DrawingArea  { 		button_press_event.connect ((t, e)=> { 			GtkWindow.reset_modifier (e.state); -			if (button_down) {-				warning (@"Button already is down. $(e.button)");-			}-			 			if (e.time < last_press) { 				warning ("Discarding event."); 				return true;@@ -738,7 +732,6 @@ public class GlyphCanvasArea : DrawingArea  { 			 			if (e.type == EventType.BUTTON_PRESS) { 				TabContent.button_press (e.button, e.x, e.y);-				button_down = true; 			} else if (e.type == EventType.2BUTTON_PRESS) { 				TabContent.double_click (e.button, e.x, e.y); 			}@@ -747,10 +740,6 @@ public class GlyphCanvasArea : DrawingArea  { 		}); 		 		button_release_event.connect ((t, e)=> {-			if (!button_down) {-				warning (@"Button is not down $(e.button)");-			}-			 			if (e.time < last_release) { 				warning ("Discarding event."); 				return true;@@ -758,10 +747,10 @@ public class GlyphCanvasArea : DrawingArea  { 			 			if (e.type == EventType.BUTTON_RELEASE) { 				TabContent.button_release ((int) e.button, e.x, e.y);-				last_release = e.time;-				button_down = false; 			} 			+			last_release = e.time;+			 			return true; 		}); 		diff --git a/libbirdfont/Renderer/TextArea.vala b/libbirdfont/Renderer/TextArea.valaindex 797c52c..9b77b38 100644--- a/libbirdfont/Renderer/TextArea.vala+++ b/libbirdfont/Renderer/TextArea.vala@@ -1660,6 +1660,44 @@ public class TextArea : Widget { 			return c; 		} 	}+	+	public override void double_click (uint button, double x, double y) {+		if (is_over (x, y)) {+			carret = get_carret_at (x, y);+			+			Paragraph paragraph = paragraphs.get (carret.paragraph);+			+			int index = carret.character_index;+			int prev_index = index;+			unichar c;+			+			while (paragraph.text.get_prev_char (ref index, out c)) {+				if (c == '\t' || c == ' ' || c == '\n') {+					break;+				}+				+				prev_index = index;+			}+			+			carret.character_index = prev_index;+			+			selection_end = carret.copy ();+			index = selection_end.character_index;+		 +			while (paragraph.text.get_next_char (ref index, out c)) {+				if (c == '\t' || c == ' ' || c == '\n') {+					break;+				}+				+				prev_index = index;+			}+			+			selection_end.character_index = prev_index;+			show_selection = selection_is_visible ();			+			+			update_selection = true;+		}+	} }  }diff --git a/libbirdfont/TableLayout.vala b/libbirdfont/TableLayout.valaindex 7699725..7dc73d3 100644--- a/libbirdfont/TableLayout.vala+++ b/libbirdfont/TableLayout.vala@@ -25,7 +25,8 @@ public class TableLayout : FontDisplay { 	public Gee.ArrayList<Widget> widgets = new Gee.ArrayList<Widget> (); 	public Gee.ArrayList<Widget> focus_ring = new Gee.ArrayList<Widget> (); 	public int focus_index = 0;-	+	bool ignore_input = true;+		 	public Widget? keyboard_focus = null; 	 	public TableLayout () {@@ -125,6 +126,11 @@ public class TableLayout : FontDisplay { 		Widget t; 		Widget old; 		CheckBox c;+				+		if (ignore_input) {+			printd (@"Ignoring extra clicks.");+			return;+		} 		 		foreach (Widget w in widgets) { 			if (w.is_over (x, y)) {@@ -172,6 +178,11 @@ public class TableLayout : FontDisplay { 	 	public override void button_release (int button, double x, double y) { 		Widget t;++		if (ignore_input) {+			printd (@"Ignoring extra clicks.");+			return;+		} 		 		if (keyboard_focus != null) { 			t = (!) keyboard_focus;@@ -231,6 +242,15 @@ public class TableLayout : FontDisplay { 	} 	 	public override void selected_canvas () {+		ignore_input = true;+		+		TimeoutSource input_delay = new TimeoutSource (250);+		input_delay.set_callback(() => {+			ignore_input = false;+			return false;+		});+		input_delay.attach (null);+		 		KeyBindings.set_require_modifier (true); 		update_scrollbar (); 		GlyphCanvas.redraw ();@@ -251,6 +271,29 @@ public class TableLayout : FontDisplay { 	public override bool needs_modifier () { 		return true; 	}+	+	public override void double_click (uint button, double x, double y) {+		Widget t;+				+		if (ignore_input) {+			printd (@"Ignoring extra clicks.");+			return;+		}+		+		if (keyboard_focus != null) {+			t = (!) keyboard_focus;+			set_focus (t);+			t.double_click (button, x, y);+		}++		foreach (Widget w in widgets) {+			if (w.is_over (x, y)) {+				w.double_click (button, x, y);+			}+		}+					+		GlyphCanvas.redraw ();+	} }  }diff --git a/libbirdfont/Widget.vala b/libbirdfont/Widget.valaindex af17532..d49f561 100644--- a/libbirdfont/Widget.vala+++ b/libbirdfont/Widget.vala@@ -69,6 +69,9 @@ public abstract class Widget : GLib.Object { 	public virtual void button_release (uint button, double x, double y) { 	} 	+	public virtual void double_click (uint button, double x, double y) {+	}	+	 	public virtual bool motion (double x, double y) { 		return false; 	}

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112