Commit Graph

41 Commits

Author SHA1 Message Date
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Lucas CHOLLET
201890e109 LibGUI: Don't call on_escape_pressed from EditingEngines
The call will be handled in `TextEditor::keydown_event`, just after that
`EditingEngine::on_key()` is called.
2023-07-14 06:52:38 +02:00
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Ben Wiederhake
560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
huttongrabiel
6926991a56 LibGUI: Delete from current position to end of line in VimEditingEngine
When in normal mode pressing Shift+D will delete from the current cursor
position to the end of the line. Leaving the cursor on the character
before where the cursor was when the deletion took place.
2022-10-12 09:46:18 -06:00
Robbie Vanbrabant
26a3b42a15 LibGUI: Add visual line mode to VimEditingEngine
Applications using the Vim emulation engine now support line-wise text
selection.

We already have support for character-wise text selection, by pressing
`v` from normal mode.

However now can also trigger line-wise text selection by pressing
`shift+v` from normal mode, and then using vertical motion commands
(e.g. `j` or `k`) to expand the selection. This is a standard vim
feature.

In visual line mode the following operations are supported:

  * `escape`: back to normal mode
  * `u`: convert to lowercase
  * `U`: convert to uppercase
  * `~`: toggle case
  * `ctrl+d`: move down by 50% of page height
  * `ctrl+u`: move up by 50% of page height
  * `d` or `x`: delete selection
  * `c`: change selection
  * `y`: copy selection
  * `page up`: move up by 100% of page height
  * `page down`: move down by 100% of page height

Notably I didn't implement pressing `v` to go to regular
(character-wise) visual mode straight from visual line mode. This is
tricky to implement in the current code base, and there's an
alternative, which is to take a detour via normal mode.
2022-08-26 12:50:30 +02:00
huttongrabiel
2cfbb9a0e8 LibGUI: Implement case inversion in Vim emulation
When in visual mode with text selected, on Key_Tilde press, uppercase
characters convert to lowercase and lowercase ones to uppercase.
2022-05-26 21:51:23 +01:00
huttongrabiel
a54b681149 LibGUI: Allow to lowercase conversion in Vim emulation
If Key_U is pressed while in visual mode, the currently selected text
will be converted to lowercase.
2022-05-26 00:33:01 +01:00
huttongrabiel
e3bef71d05 LibGUI: Allow to uppercase conversion in Vim emulation
If Shift+Key_U is pressed while in visual mode, the currently selected
text will be converted to uppercase.
2022-05-26 00:33:01 +01:00
huttongrabiel
45c5f68d8a LibGUI: Add casefold_selection function to choose case conversion
Allows the passing of a Casing enum, Lowercase or Uppercase, and
converts the selected text accordingly. If Lowercase is passed as the
parameter, it converts the selected text to lowercase. If Uppercase is
passed as the parameter, it converts the selected text to uppercase.
2022-05-26 00:33:01 +01:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
scwfri
dbd40e4c2a LibGUI: Implement vim motions for LeftBrace and RightBrace
In VimEditingEngine, implemented vim motions for Key_LeftBrace and
Key_RightBrace
2021-11-30 10:55:19 +01:00
Ben Wiederhake
2f023acf78 LibGUI: Convert always-valid pointer to reference
The pointer is always assumed to be non-null, so let's change it to a
reference.
2021-10-15 10:38:57 +02:00
Andreas Kling
6ad427993a Everywhere: Behaviour => Behavior 2021-09-07 13:53:14 +02:00
Daniel Bertalan
db840aaacd LibGUI: Add break even before empty default label
Clang is a bit more pedantic than GCC when diagnosing implicit
fallthroughs, and doesn't care if the succeeding label only contains a
single break statement.
2021-08-08 10:55:36 +02:00
Ariel Don
54bf6a7884 LibGUI: Add Ctrl-U to insert mode
While under insert mode, Ctrl-U deletes all characters between the first
non-blank character of the line and the cursor.

Implement delete_from_line_start_to_cursor() in TextEditor. Then, call
the method in VimEditingEngine via its pointer to an instance of
TextEditor.
2021-07-20 03:22:28 +02:00
Ariel Don
8230bf8944 LibGUI: Add Ctrl-H to insert mode
In Vim, Ctrl-H is effectively equivalent to backspace in insert mode, as
it deletes the previous character.

This commit implements method delete_previous_char() to TextEditor.
delete_char() already exists in EditingEngine, but it deletes the
next character rather than the previous. delete_previous_char() is then
called from within VimEditingEngine.
2021-07-20 03:22:28 +02:00
Ariel Don
808e5e813f LibGUI: Add Ctrl-W to insert mode
In Vim's insert mode, Ctrl-W deletes the word before the cursor, like
Ctrl-Backspace. Unlike Ctrl-Backspace, if only whitespace exists between
the end of the word and the cursor, the word will be deleted with the
whitespace.

To do so, this commit introduces two methods: delete_previous_word() for
TextEditor and first_word_before() for TextDocument, where the former
depends on the latter. delete_previous_word() is then called in
VimEditingEngine.
2021-07-20 03:22:28 +02:00
Matthew Hall
3b5b7c5e65 VimEditingEngine: Add support for repeats of J 2021-07-15 10:10:07 +02:00
Matthew Hall
2653ad36ee VimEditingEngine: Add support for repeats of p and P 2021-07-15 10:10:07 +02:00
Matthew Hall
7b7548ce9d VimEditingEngine: Allow repeats for dd, yy and x 2021-07-15 10:10:07 +02:00
Matthew Hall
c1e2710a0d VimEditingEngine: Add P command to put before cursor 2021-07-15 10:10:07 +02:00
Matthew Hall
180e2469af VimEditingEngine: Add J command to join two lines 2021-07-15 10:10:07 +02:00
Matthew Hall
a7e7f62d08 VimEditingEngine: Operate on real lines rather than wrapped ones
In the normal editing engine keys like Home, End etc work on visual
lines, but vim operates on real ones. Eg if you have a really long line
and wrapping is on then in normal editing Home would take you to the
beginning of the wrapped line, but 'I' would put you insert mode at the
beginning of the real line in vim.
2021-07-15 10:10:07 +02:00
Paul Berg
03d8ee1082 VimEditingEngine: allow selection of the endline character
This patch fixes the visual selection of endline characters in the
VimEditingEngine. When the visual mode is disabled and the cursor
is located on the endline character, it is shifted back to the last
character of the line.
2021-04-27 19:05:16 +02:00
sin-ack
ace2c337dc VimEditingEngine: Handle arrow, Home/End and Page keys
This patch adds handling of the arrow, Home/End, and PageUp/PageDown
keys to the Vim emulation mode.  Home acts as 0, End acts as $, arrow
keys act as their HJKL variants, and PageUp/Down behaves as you would
expect.

This patch also moves the default handling of the aforementioned keys
to insert mode, since regular EditingEngine semantics are more
appropriate there.
2021-04-27 13:10:10 +02:00
sin-ack
d6dc81874d EditingEngine: Split selection from movement functions
This patch moves selection updates outside movement functions in
EditingEngine.  Previously, movement functions would automatically
update the selection based on whether the Shift key was pressed down
during movement.  However, not all EditingEngine subclasses want that;
VimEditingEngine being a good example (because all selection is handled
in visual mode).

Therefore, this patch moves all selection updating to
EditingEngine::on_key().  Subclasses wishing to provide custom movement
and selection semantics should override it (and VimEditingEngine already
does).
2021-04-27 09:03:38 +02:00
Linus Groh
dbe72fd962 Everywhere: Remove empty line after function body opening curly brace 2021-04-25 20:20:00 +02:00
sin-ack
53aec3e06d LibGUI: Implement Vim motion system
This patch implements Vim motions.  The VimMotion class will accept
keycodes from the editing engine to build up a motion, and will
signal when a motion is complete via VimMotion::is_complete().  The
editing engine can then call VimMotion::get_range() to obtain a
TextRange object which can be used to perform operations on the text,
or VimMotion::get_position() to obtain a TextPosition which is the
new position of the cursor after the motion.

Currently, the following motions are supported:

- h/j/k/l, regular Vim line and character movements
- 0/^/$, start/end of line and start of non-blank
- w/e/b/ge, word-related movements
- W/E/B/gE, WORD (anything non-blank) versions of the above motions
- gg/G, document related movements
- t/f, to/find character

All motions except gg/G accept a number prefix to repeat the motion that
many times.

This patch updates insert, normal and visual modes to use this motion
system for movement.
2021-04-25 10:41:16 +02:00
Rok Povsic
77d4b6e435 VimEditingEngine: Add handling { and } to move between empty lines 2021-04-25 09:34:51 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
31e04907b4 Revert "TextEditor: Add vim status indicators to the statusbar"
This reverts commit bd6d0d2295.
2021-02-02 19:01:54 +01:00
Zac
bd6d0d2295 TextEditor: Add vim status indicators to the statusbar
When using the VimEditingEngine in the TextEditor, vim's mode and the
previous key are shown in the editor's statusbar.
2021-02-02 16:08:20 +01:00
Zac
aaf691c4ef Vim: Add change word and delete word functionality
Add the functionality of key sequences 'cw', 'ce', 'cb', 'dw', 'de' and 'db'.
2021-01-28 08:17:02 +01:00
Zac
b56ef9042b Vim: Add a simple yank and put implementation 2021-01-25 22:31:43 +01:00
Zac
330ab52ddb
Vim: More correct word jumping (#5090)
Implemented move_to_beginning_of_next(), move_to_end_of_next(),
move_to_beginning_of_previous() and move_to_end_of_previous() functions
for more correct word jumping than the move_to_xxx_span() methods that
were previously used.
2021-01-24 19:24:56 +01:00
Zac
dfa3f5fbc8 Vim: Added a Basic Implementation of Visual Mode 2021-01-23 08:29:13 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00