[polari] tabCompletion: Use cursor extents for positioning popover



commit 440f2a7a86bc42c18208ef1aeafd8f9dd49f0af8
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 8 01:00:30 2021 +0200

    tabCompletion: Use cursor extents for positioning popover
    
    In GTK4, entries no longer expose the underlying pango layout. There is
    a dedicated API for retrieving the cursor extents at a give character
    position though, start using that (via the polyfill).
    
    Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/228>

 src/tabCompletion.js | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
---
diff --git a/src/tabCompletion.js b/src/tabCompletion.js
index b56a7b5c..fa5098b2 100644
--- a/src/tabCompletion.js
+++ b/src/tabCompletion.js
@@ -1,6 +1,5 @@
 import Gdk from 'gi://Gdk';
 import Gtk from 'gi://Gtk';
-import Pango from 'gi://Pango';
 
 import * as IrcParser from './ircParser.js';
 
@@ -53,16 +52,12 @@ export default class TabCompletion {
     _showPopup() {
         this._list.show();
 
-        let layout = this._entry.get_layout();
-        let layoutIndex = this._entry.text_index_to_layout_index(this._startPos);
-        let wordPos = layout.index_to_pos(layoutIndex);
-        let [layoutX] = this._entry.get_layout_offsets();
+        const delegate = this._entry.get_delegate();
+        const [extents] = delegate.compute_cursor_extents(this._startPos);
+        const [, bounds] = this._entry.compute_bounds(delegate);
 
         this._popup.pointing_to = new Gdk.Rectangle({
-            x: layoutX + wordPos.x / Pango.SCALE,
-            y: 0,
-            width: 1,
-            height: 1,
+            x: extents.get_x() - bounds.get_x(),
         });
         this._popup.popup();
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]