yquake2 / yquake2

The Yamagi Quake II client
https://www.yamagi.org/quake2/
Other
857 stars 219 forks source link

Clipboard support in console #1131

Open OpenRift412 opened 4 months ago

OpenRift412 commented 4 months ago

Just a minor QoL feature. Weirdly enough, this is a feature in vanilla 3.20, but somehow isn't here? Is there a reason for that?

protocultor commented 3 months ago

"Extension" of #964 ? A possible reason it works in 3.20 is that the game probably uses native / OS input for keyboard, while YQ2 uses SDL for cross-platform compatibility.

BjossiAlfreds commented 3 months ago

It shouldn't be difficult to set up a wrapper function that hides platform dependent clipboard implementations using ifdefs. The Windows API is fairly simple. The other part to this is detecting Ctrl+V input. I haven't looked if this code is already in place or we need to write it ourselves.

BjossiAlfreds commented 3 months ago

I spent some time studying the keyboard/console code and experiments today and got CTRL actions in console to work again, including old code for a CTRL+L that I didn't even know existed, to clear the console.

It seems that when CTRL is held down, pressing other keys counts as a key up/down event rather than text input. This causes Key_Event to be called with special == false which prevents the event from reaching Key_Console. I don't understand this code well enough to address this properly so I did a small hack that flips special to true if CTRL is being held while in the console and key is an alphabet letter.

I then wrote quick little code that uses SDL_GetClipboardText() and attached it to CTRL+v.

Finally, since I had seen requests for this before, I separated backspace from left/right arrow so you can move the cursor inside the edit line.

I got this in my con-ext branch: https://github.com/BjossiAlfreds/yquake2/tree/con-ext

If you are interested @Yamagi I can PR. Needs thorough testing.

EDIT: Added CTRL+x and CTRL+c to cut/copy input line to clipboard. And made the delete key work again, deleting the character the cursor is on.

Yamagi commented 3 months ago

A long time ago I planed to replace the home grown line editor in the console with linenoise: https://github.com/antirez/linenoise For one reason or the other it never happened.

If you are interested @Yamagi I can PR. Needs thorough testing.

Yes please :) We should merge this early in the current release because, because as you said. It needs testing, the console is fragile...

jobukkit commented 1 month ago

Would be nice for pasting server IP's into the address book too.

BjossiAlfreds commented 1 month ago

I took a quick look at the menu input field code and it seems pretty straight-forward. I went ahead and adopted my line editing extensions for the menu fields (left/right arrow navigation), and I'll see if I can get the clipboard stuff working as well.

BjossiAlfreds commented 1 month ago

Just made a PR for clipboard support + in-line editing in menu input fields: https://github.com/yquake2/yquake2/pull/1157