Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word-wise text-navigation not working #16

Closed
Saduras opened this issue Dec 10, 2019 · 16 comments
Closed

Word-wise text-navigation not working #16

Saduras opened this issue Dec 10, 2019 · 16 comments
Labels
bug Something isn't working

Comments

@Saduras
Copy link

Saduras commented Dec 10, 2019

First of all thanks a lot for your work. I struggled for some time how to modify my keymaps and hotkeys to match the mac-style until I found your project which solved it quickly.

But unfortunately word-wise navigation (alt - left-arrow / alt - right arrow on mac) is not working for me. I saw the issue #2 where you already addressed this but it does not work for me.

I'm running Ubuntu 18.04 with x11 on a 2014 MacBook Pro.

Can you help me figure out why it's not working? Thanks!

@rbreaves
Copy link
Owner

I will take a look at this tomorrow, sorry for the delayed response.

@rbreaves
Copy link
Owner

rbreaves commented Jan 29, 2020

I just tested this out under sublime text and it appears to behave the same as macOS sublime text vs Ubuntu 18.04 sublime text.

The way the alt and arrow keys are handled per app under Linux I believe is simply different than how macOS typically handles it for its applications (devs following stricter standards, using specific libraries, etc.).

If someone can indicate to me otherwise, that there would be a reason to further pursue this by updating this file then please let me know, but I don't think there is much I can do to further Alt + arrow compatibility.
https://github.com/rbreaves/kinto/blob/master/.xkb/symbols/mac_gui

I have just added kintox11, a C based program, that handles a lot better than xprop and can easily be sent a basic text file of terminal app names so it can output whether the user is using a term or gui based app. kintox11 could easily be extended to all support custom keymaps (symbol files) based on another set of criteria, perhaps looking for conf files with the application name itself.

The source and files are currently up on the dev branch while I work on it.
git checkout 2d69c7b

** Updated **
kintox11 is in the master branch and the defaults.json or user_config.json files can be modified to support any additional keymappings.

@bravokiloecho
Copy link

bravokiloecho commented Feb 8, 2020

Hello! I'm just entering the world of linux and ubuntu from a Mac OS and this project is saving me from so much keyboard grief! But I'm also experiencing this lack of word-wise text navigation.

In VS Code on Mac OS (and all other GUI software) I'm used to Alt + Left/Right moving the cursor to the end of words. However, in Ubuntu with Kinto on, Alt + left does nothing in VS Code, and in firefox triggers the browser back.

I'm not sure exactly whether you were suggesting this was fixed, or going to be fixed, but I would love if there was a system-wide way of handling this.

Many thanks for all your work on this so far!

@cicloon
Copy link

cicloon commented Feb 10, 2020

Same here, word navigation is the only thing I'm missing so far. Having this would be great.

@rbreaves rbreaves reopened this Feb 11, 2020
@rbreaves
Copy link
Owner

I'll re-open the issue and take another look at it since you are specifically mentioning the program you are having an issue with. I'll compare it with the macOS program of VS code, there may be a difference with specific apps, I just couldn't duplicate an issue in sublime text, but maybe we're not talking the exact some set of keys - either way I will take another look.

@bravokiloecho
Copy link

That's really great, thanks so much!

And just to clarify, this alt + left/right behaviour of word navigation is pretty much system-wide in Mac OS (see the "Working with text" section on this page: https://www.danrodney.com/mac/#working-with-text). It's also documented here: https://support.apple.com/en-za/HT201236

So ideally this would be system wide in Linux also, apart from in the Terminal which I realise is a special case.

One more note that might help... The original key combo to do this in Ubuntu is Ctrl + left/right and is documented here as "Go to previous/next word" https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts#Text_editing

@rbreaves
Copy link
Owner

As I was trying to explain earlier, making Alt + left/right a system-wide navigation feature will be exceedingly difficult, if not impossible on Linux due to the lack of consensus btwn developers on the platform.

I have installed VS Code now under linux and tested this out and appears like Alt + Left/Right is dedicated already to terminal pane focus usage, but if you remove those keymaps you can then rebind the Ctrl + Left/Right keybindings to traverse words as you are wanting. I might include some default keybindings with the install of Kinto, but currently it is outside the scope of the project, which is to focus on fixing global keymap type issues. However including some default macOS like keymaps for specific apps during and after the install is something I may be interested in doing later - it's just a lot more effort since they'd all be one off efforts.

It is apparent though that the Ctrl+Left/Right is overridden in VS Code by the Kinto remap effort to make Ctrl+Left/Right behave more like it does on macOS.

Screen Shot 2020-02-11 at 4 58 42 PM

~/.config/Code/User/keybindings.json

// Place your key bindings in this file to override the defaultsauto[]
[
    {
        "key": "alt+left",
        "command": "-workbench.action.terminal.focusPreviousPane",
        "when": "terminalFocus"
    },
    {
        "key": "alt+left",
        "command": "cursorWordStartLeft",
        "when": "textInputFocus"
    },
    {
        "key": "ctrl+left",
        "command": "-cursorWordStartLeft",
        "when": "textInputFocus"
    },
    {
        "key": "alt+right",
        "command": "-workbench.action.terminal.focusNextPane",
        "when": "terminalFocus"
    },
    {
        "key": "alt+right",
        "command": "cursorWordEndRight",
        "when": "textInputFocus"
    },
    {
        "key": "ctrl+right",
        "command": "-cursorWordEndRight",
        "when": "textInputFocus"
    }
]

@bravokiloecho
Copy link

I see, I don't think I understood that you were saying it wasn't possible earlier. And I agree that application specific keybindings is probably outside the scope of Kinto. But thank you for the help of VS Code, that certainly makes things better.

However I still find it strange that there can be no way of word-wise navigation. It works with ctrl + right/left without Kinto. Is there no way of mapping it to something? Even the default behaviour? It would be a real shame to lose this functionality completely as it makes typing much harder.

@owzim
Copy link

owzim commented Feb 12, 2020

It works with ctrl + right/left without Kinto.

So the functionality IS there but borked by kinto. This is clearly a bug then @rbreaves?

Looking at this list of shortcuts it IS listed under section 'Working With Words'. I formerly thought this functionality is missing on linux.

@rbreaves
Copy link
Owner

rbreaves commented Feb 12, 2020

Deleting my overly long comment.. hmmm. Maybe there is something I can do here after all. Thanks for that link @owzim.. for some reason I was pretty certain there wasn't anything comparable but maybe.. maybe I was wrong about that. I will look into this more.

And looking at the original sublime text config file I might not be breaking wordwise still, even though it supports traversing words already by default, even with alt.

@rbreaves
Copy link
Owner

rbreaves commented Feb 12, 2020

I am going to re-open this issue to give it more visibility in hopes that someone might have some ideas on how to fix the symbols and types files as I am beginning to think that this might actually have a solution it just escapes me at this time.

This is one approach that I have seen and commented on in the past that appears to tackle it, but in the exact opposite way that I am solving it with Kinto. Kinto checks for when your focus window changes and the reset your keyboard layout, no key interception going on at all.

This guy's approach intercepts every single keystroke and checks it against the app with the current focus and then decides whether or not to remap your key input. The approach works.. but comparatively it is a very brutefroce approach to make things work. I am not criticizing it, it should work in theory, but I also couldn't ever figure out how to get his script to actually run either.

https://github.com/joeytwiddle/dotfiles/blob/master/.config/sxhkd/sxhkdrc

baskerville/sxhkd#123


To fix my approach these two files will need to updated or duplicated for testing, it'll probably be easier to duplicate them and get rid of the Ctrl remapping stuff while working out how to remap Alt + arrow keys.

https://github.com/rbreaves/kinto/blob/master/.xkb/symbols/mac_gui
https://github.com/rbreaves/kinto/blob/master/.xkb/types/mac_gui

And to repeat what I said in that thread for sxhkd.

There is a 3rd file that'll be created in ~/.xkb/keymaps/kbd.mac.gui, it looks something like the following (depending on your keyboard type)

xkb_keymap {
	xkb_keycodes  { include "evdev+aliases(qwerty)"	};
	xkb_types     { include "complete+mac_gui(addmac_levels)"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+us+us:2+inet(evdev)+ctrl(swap_lwin_lctl)+ctrl(swap_rwin_rctl)+mac_gui(mac_levelssym)"	};
	xkb_geometry  { include "pc(pc105)"	};
};

I have tried modifying them so that I have a level modifier for alt in the same manner I have one for control, but it just seems to fail to work. One of the many difficulties of working with xkb.


3rd option
I've tried this one too and after some difficulty I got it only sorta working.. keys seems to get stuck with it a lot or maybe I am not running the remap function properly.
https://github.com/boppreh/keyboard

#!/usr/bin/env python3
import keyboard

# keyboard.remap_hotkey(src, dst, suppress=True, trigger_on_release=False)
keyboard.remap_hotkey('alt+left', 'ctrl+left')
keyboard.remap_hotkey('alt+right', 'ctrl+right')

# Block forever, like `while True`.
keyboard.wait()



@rbreaves rbreaves reopened this Feb 12, 2020
@rbreaves
Copy link
Owner

rbreaves commented Feb 13, 2020

Ok guys.. @owzim, @bravokiloecho, @cicloon, @Saduras and @probonobp the Alt key will now move the cursor to the left or right of the current word in the same manner as macOS. (works in VS Code and it still works in Sublime as sublime has support for both mappings by default)

I am FINALLY closing this ticket!! lol Let me know though if what's in master, 1.0.5, doesn't solve it for you guys though and I'll reopen the ticket, but I am pretty sure this update knocks it out.

5d135af


And just to reference this interesting thread from 2015. They talked about this very solution way back then, but the people in the thread never really got it figured out and working sadly, they were headed in the right direction though.

https://geekhack.org/index.php?topic=70788.0

@bravokiloecho
Copy link

Hi @rbreaves, I'm so grateful to all your work and thinking on this issue; truly impressive. And apologies for being so slow on replying to this...

I pulled the latest version from master and ran the install process again, however nothing seems to have changed wrt the alt + arrow keys for me. I had already setup the custom keybindings in VS Code (as you described) so it was working there before. But for example, in this textarea on Github, they don't work.

Should it be working here, or were you just making a fix for VS Code? Apologies if I've misunderstood something.

@rbreaves
Copy link
Owner

I’m up way too late, will have to look into it a bit later. Word-wise in browsers is not released yet, chrome is very problematic as it uses Alt arrows for back & forwards.

VS Code should already be working in master & dev unless I did something wrong in the keyswap_service.sh file that copies the files over.. I did notice my dev machine I don’t think was updating the ~/.xkb on subsequent installs. Maybe delete that directory & reinstall.

@bravokiloecho
Copy link

Manually deleting the ./xkb seemed to have done it! It looks to be working pretty good! So exciting!! Thank you!!!!!

@rbreaves
Copy link
Owner

rbreaves commented Feb 18, 2020

@owzim, @bravokiloecho, @cicloon, @Saduras and @probonobp Another release 1.0.5-2 has just landed if any of you guys want to check it out. This directly addresses wordwise while using web browsers and still keeping the Cmd + Arrow keys working with Back and Forwards, just like macOS, while no text field is highlighted.

Also fixed the installer to properly overwrite the .xkb directory this time.

@rbreaves rbreaves added the bug Something isn't working label Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants