mirror of
https://github.com/danbulant/dots-hyprland
synced 2026-05-24 20:31:57 +00:00
overview: add ctrl b ctrl k ctrl n for text manipulation (#255)
This commit is contained in:
parent
b7865e5874
commit
bec26cba7d
1 changed files with 26 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
const { Gtk } = imports.gi;
|
||||
const { Gdk, Gtk } = imports.gi;
|
||||
import App from 'resource:///com/github/Aylur/ags/app.js';
|
||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||
|
|
@ -236,10 +236,31 @@ export const SearchAndWindows = () => {
|
|||
}
|
||||
})
|
||||
.on('key-press-event', (widget, event) => { // Typing
|
||||
if (event.get_keyval()[1] >= 32 && event.get_keyval()[1] <= 126 && widget != entry) {
|
||||
Utils.timeout(1, () => entry.grab_focus());
|
||||
entry.set_text(entry.text + String.fromCharCode(event.get_keyval()[1]));
|
||||
entry.set_position(-1);
|
||||
const keyval = event.get_keyval()[1];
|
||||
const modstate = event.get_state()[1];
|
||||
if (modstate & Gdk.ModifierType.CONTROL_MASK) { // Ctrl held
|
||||
if (keyval == Gdk.KEY_b)
|
||||
entry.set_position(Math.max(entry.get_position() - 1, 0));
|
||||
else if (keyval == Gdk.KEY_f)
|
||||
entry.set_position(Math.min(entry.get_position() + 1, entry.get_text().length));
|
||||
if (keyval == Gdk.KEY_n) { // simulate Down arrow
|
||||
entry.get_root_window().simulate_key_press(Gdk.KEY_Down, Gdk.ModifierType.NONE);
|
||||
// entry.get_root_window().simulate_key_release(Gdk.KEY_Down, Gdk.ModifierType.NONE);
|
||||
}
|
||||
if (keyval == Gdk.KEY_k) { // Delete to end
|
||||
const text = entry.get_text();
|
||||
const pos = entry.get_position();
|
||||
const newText = text.slice(0, pos);
|
||||
entry.set_text(newText);
|
||||
entry.set_position(newText.length);
|
||||
}
|
||||
}
|
||||
else { // Ctrl not held
|
||||
if (keyval >= 32 && keyval <= 126 && widget != entry) {
|
||||
Utils.timeout(1, () => entry.grab_focus());
|
||||
entry.set_text(entry.text + String.fromCharCode(keyval));
|
||||
entry.set_position(-1);
|
||||
}
|
||||
}
|
||||
})
|
||||
,
|
||||
|
|
|
|||
Loading…
Reference in a new issue