aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/chat_input
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui/chat_input')
-rw-r--r--main/src/ui/chat_input/chat_input_controller.vala4
-rw-r--r--main/src/ui/chat_input/chat_text_view.vala38
-rw-r--r--main/src/ui/chat_input/smiley_converter.vala2
3 files changed, 35 insertions, 9 deletions
diff --git a/main/src/ui/chat_input/chat_input_controller.vala b/main/src/ui/chat_input/chat_input_controller.vala
index 41891519..b60a17d4 100644
--- a/main/src/ui/chat_input/chat_input_controller.vala
+++ b/main/src/ui/chat_input/chat_input_controller.vala
@@ -34,7 +34,7 @@ public class ChatInputController : Object {
reset_input_field_status();
- var text_input_key_events = new EventControllerKey();
+ var text_input_key_events = new EventControllerKey() { name = "dino-text-input-controller-key-events" };
text_input_key_events.key_pressed.connect(on_text_input_key_press);
chat_input.chat_text_view.text_view.add_controller(text_input_key_events);
@@ -192,7 +192,7 @@ public class ChatInputController : Object {
activate_last_message_correction();
return true;
} else {
- chat_input.chat_text_view.text_view.grab_focus();
+ chat_input.do_focus();
}
return false;
}
diff --git a/main/src/ui/chat_input/chat_text_view.vala b/main/src/ui/chat_input/chat_text_view.vala
index 437950ea..3752a1cf 100644
--- a/main/src/ui/chat_input/chat_text_view.vala
+++ b/main/src/ui/chat_input/chat_text_view.vala
@@ -34,16 +34,18 @@ public class ChatTextView : Box {
public signal void send_text();
public signal void cancel_input();
- public ScrolledWindow scrolled_window = new ScrolledWindow() { propagate_natural_height=true, max_content_height=300 };
+ public ScrolledWindow scrolled_window = new ScrolledWindow() { propagate_natural_height=true, max_content_height=300, hexpand=true };
public TextView text_view = new TextView() { hexpand=true, wrap_mode=Gtk.WrapMode.WORD_CHAR, valign=Align.CENTER, margin_top=7, margin_bottom=7 };
private int vscrollbar_min_height;
+ private uint wait_queue_resize;
private SmileyConverter smiley_converter;
construct {
+ valign = Align.CENTER;
scrolled_window.set_child(text_view);
this.append(scrolled_window);
- var text_input_key_events = new EventControllerKey();
+ var text_input_key_events = new EventControllerKey() { name = "dino-text-input-view-key-events" };
text_input_key_events.key_pressed.connect(on_text_input_key_press);
text_view.add_controller(text_input_key_events);
@@ -52,20 +54,44 @@ public class ChatTextView : Box {
scrolled_window.vadjustment.changed.connect(on_upper_notify);
text_view.realize.connect(() => {
- var minimum_size = new Requisition();
+ var minimum_size = Requisition();
scrolled_window.get_preferred_size(out minimum_size, null);
vscrollbar_min_height = minimum_size.height;
});
}
+ public override void dispose() {
+ base.dispose();
+ if (wait_queue_resize != 0) {
+ Source.remove(wait_queue_resize);
+ wait_queue_resize = 0;
+ }
+ }
+
private void on_upper_notify() {
// hack. otherwise the textview would only show the last row(s) when entering a new row on some systems.
- if (text_view.get_height() < scrolled_window.max_content_height - 20) {
- scrolled_window.vadjustment.page_size = scrolled_window.vadjustment.upper;
- }
+ scrolled_window.height_request = int.min(scrolled_window.max_content_height, (int) scrolled_window.vadjustment.upper + text_view.margin_top + text_view.margin_bottom);
+ scrolled_window.vadjustment.page_size = double.min(scrolled_window.height_request - (text_view.margin_top + text_view.margin_bottom), scrolled_window.vadjustment.upper);
// hack for vscrollbar not requiring space and making textview higher //TODO doesn't resize immediately
scrolled_window.get_vscrollbar().visible = (scrolled_window.vadjustment.upper > scrolled_window.max_content_height - 2 * this.vscrollbar_min_height);
+ start_queue_resize_if_needed();
+ }
+
+ private void start_queue_resize_if_needed() {
+ if (wait_queue_resize == 0) {
+ wait_queue_resize = Timeout.add(100, queue_resize_if_needed);
+ }
+ }
+
+ private bool queue_resize_if_needed() {
+ if (scrolled_window.get_height() == scrolled_window.height_request) {
+ wait_queue_resize = 0;
+ return false;
+ } else {
+ queue_resize();
+ return true;
+ }
}
private bool on_text_input_key_press(uint keyval, uint keycode, Gdk.ModifierType state) {
diff --git a/main/src/ui/chat_input/smiley_converter.vala b/main/src/ui/chat_input/smiley_converter.vala
index fe280d99..ea0483e9 100644
--- a/main/src/ui/chat_input/smiley_converter.vala
+++ b/main/src/ui/chat_input/smiley_converter.vala
@@ -33,7 +33,7 @@ class SmileyConverter {
public SmileyConverter(TextView text_input) {
this.text_input = text_input;
- var text_input_key_events = new EventControllerKey();
+ var text_input_key_events = new EventControllerKey() { name = "dino-smiley-converter-key-events" };
text_input_key_events.key_pressed.connect(on_text_input_key_press);
text_input.add_controller(text_input_key_events);
}