Commit graph

98 commits

Author SHA1 Message Date
thankyouverycool
96895cd22c Everywhere: Fully qualify font names by including their slope
Fixes typefaces of the same weight but different slopes being
incorrectly returned for each other by FontDatabase.
2022-02-01 10:06:26 +01:00
Tobias Christiansen
92e337de21 LibGUI: Fix typo in TextEditor 2022-01-23 22:12:05 +00:00
Tobias Christiansen
9a28c8dc74 LibGUI: Fix broken text rendering in TextEditor
This patch reintroduces the translation previously mistakenly removed
when adding support for different underline-styles.

Thanks for reporting the bug, kennethmyhra!
2022-01-23 22:12:05 +00:00
Tobias Christiansen
5348c67ba4 LibGUI: Expand underline support for Spans in TextEditor
To achieve this, some of the lambdas got shifted around and the new
attributes are respected.
2022-01-23 15:48:27 +03:30
Maciej
b6d6cc5de4 LibGUI: Use Font::glyph_or_emoji_width() in TextEditor
This fixes selection of text containing emoji when variable-width font
is set.
2022-01-22 00:26:23 +00:00
Mustafa Quraish
f674102447 TextEditor: Use FileSystemAccessClient::try_* APIs 2022-01-20 10:39:12 +01:00
Marcus Nilsson
315e1c705f LibGUI: Don't paint text cursor if TextEditor is disabled
This looked a bit odd in the rare case of disabling a focused
TextEditor.
2022-01-11 16:00:48 +01:00
Young-Jin Park
9d74659f3b LibGUI: Fix leading whitespaces when text is wrapped
This commit should fix a bug where using leading whitespaces when a line
is wrapped results in a crash. Now it should correctly highlight the
leading whitespaces even when the leading whitespaces are longer than a
line.
2021-12-30 14:34:01 +01:00
Ben Wiederhake
f22c0ffe0c LibGUI+Everywhere: Make sync requests to Clipboard server more obvious 2021-11-21 11:49:06 +00:00
Ben Wiederhake
06f140a025 LibGUI: Avoid access to Clipboard server, clipboard text is never empty
The clipboard cannot reasonably contain the empty string. The clipboard
can be empty (i.e. cleared), sure, but that this check was about whether
the clipboard contained the empty string.

This cannot easily happen for two reasons:
- TextEditor GUI elements disable their copy actions when the selection
  is empty.
- Clipboard::set_data, through which all text-copying operates,
  implicitly forbids empty strings, because Process::sys$anon_create
  forbids empty anonymous files.
- Even if it were sent (e.g. by creating a non-empty anonymous file and
  sending it manually to the Clipboard server), it would not be
  received, because decode(Decoder&, Core::AnonymousBuffer&) goes
  through mmap() with a size of 0, which also is forbidden by the
  Kernel.

In other words, if the clipboard is never the empty text, therefore
checking this condition is pointless, and we can save a roundtrip to the
Clipboard server.
2021-11-21 11:49:06 +00:00
Ben Wiederhake
c80dcc4671 LibGUI: Make paste access to Clipboard atomic
This avoids data race issues and saves a synchronous request to the
ClipboardServer.
2021-11-21 11:49:06 +00:00
Andrew January
c0d6e37ab3 LibGUI: Add support for Ctrl+Delete in TextEditor
Allow deleting the word after the cursor using Ctrl+Delete in a similar
manner to how Ctrl+Backspace deletes the word before the cursor.
2021-11-13 12:53:29 +01:00
Andrew January
22e80bae29 LibGUI: Change delete key handling from action to keydown_event
Having the delete key handling be done via an action limits our ability
to support key modifiers (e.g. ctrl+delete deleting the word in front of
the cursor).

The fact that it was an action _did_ allow us to have a delete button in
the TextEditor UI. However, this is an odd choice in the first place
that isn't common in other text editors, so I just removed it.
2021-11-13 12:53:29 +01:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling
235f39e449 LibGfx: Use ErrorOr<T> for Bitmap::try_load_from_file()
This was used in a lot of places, so this patch makes liberal use of
ErrorOr<T>::release_value_but_fixme_should_propagate_errors().
2021-11-08 00:35:27 +01:00
thislooksfun
7a2c8452f1 LibGUI: Don't re-trigger the autocomplete box when the timer fires
Previously there was a situation where the autocomplete box would
appear to "jump" to the side. This was due to the following race
condition:

1. Start typing, thus triggering the autocomplete timer to start
2. Manually trigger autocomplete before the timer finishes
3. Continue typing
4. The autocomplete timer now fires

When the timer fires it causes the autocomplete box to show, which, if
it is already shown, has the effect of moving the box to the current
cursor position.
2021-11-02 17:53:22 +01:00
thislooksfun
d5baf1c1fa LibGUI: Allow autocomplete to stay open after applying
Previously the autocomplete box would always close after applying a
suggestion. This is the desired behavior in almost all cases, but there
are some situations (like autocompleting paths) where it would be nicer
to keep the autocomplete box open after applying the suggestion.
2021-11-02 17:53:22 +01:00
thislooksfun
352f593958 LibGUI: Add and use TextEditor::hide_autocomplete()
There were cases where the autocomplete box was being hidden but the
autocomplete timer wasn't being cancelled.
2021-11-02 17:53:22 +01:00
thislooksfun
aea9ba3b42 LibGUI: Refactor out common code
This is prepping for a future commit.
2021-11-02 17:53:22 +01:00
thislooksfun
86ea41970d LibGUI: Hide autocomplete on any event other than typing
Moving the cursor to a different location, by any means, should
dismiss the autocomplete popup. This is the behavior of virtually
every editor/IDE out there, and it is really annoying (and
confusing) when our autocomplete doesn't behave like that.
2021-11-02 17:53:22 +01:00
thislooksfun
0627ed9900 LibGUI: Always show a box when the user requests autocomplete
Previously if there were no suggestions, we simply wouldn't show the
autocomplete popup at all. This is functional, but when there are no
resultes it does leave the user wondering if it actually worked.

Now, if the user requests autocomplete and we do have requests, it
behaves exactly as before, but if there' aren't any we now show a box
with the message "No suggestions" to show the user that we got the
request, there just isn't anything to suggest.
2021-11-02 17:53:22 +01:00
Filiph Sandström
d6a0726302 Everywhere: Rename left/right-click to primary/secondary
This resolves #10641.
2021-10-27 22:05:58 +03:00
Andreas Kling
649cb67f28 LibGUI: Don't paint TextEditor selection in non-focused widgets
Showing the selection in non-focused text editors was not really useful,
since refocusing the widget would clear or change the selection
immediately anyway.

Note that TextEditors in inactive windows can still be the focused
widget within that window, and will still be painted with an "inactive"
looking selection.
2021-10-21 23:23:25 +02:00
Peter Elliott
c19d868a3e LibGUI: Don't render placeholders as secret
before my placeholder 'password' showed up as '********'.
2021-10-17 22:18:48 +02: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
thankyouverycool
92fffc3abc LibGUI: Rename CallOnChange => AllowCallback and implement elsewhere
This is a helpful option to prevent unwanted side effects, distinguish
between user and programmatic input, etc. Sliders and SpinBoxes were
implementing it idiosyncratically, so let's generalize the API and
give Buttons and TextEditors the same ability.
2021-09-22 21:35:42 +02:00
thankyouverycool
46043b71cb LibGUI: Add number_of_words() to TextEditors
Returns the total number of words in a document.
2021-09-19 00:21:37 +02:00
thankyouverycool
9a5a9fbee0 LibGUI+TextEditor: Allow cursor line highlighting to be toggled 2021-09-11 19:22:14 +02:00
sin-ack
8ea22121ac Userland: Migrate to argument-less deferred_invoke
Only one place used this argument and it was to hold on to a strong ref
for the object. Since we already do that now, there's no need to keep
this argument around since this can be easily captured.

This commit contains no changes.
2021-09-02 03:47:47 +04:30
Rob Ryan
34a64ed25b LibGUI+Browser: Add UrlBox class
This allows the address bar to "select all" when initially gaining focus
as Firefox and Chrome do. A future improvement on this would be for the
Widget class to mange and provide focus transition as part of the events
instead of the UrlBox class. Currently focus is updated before the event
is provided to the UrlBox class.
2021-08-18 10:39:13 +02:00
Gunnar Beutner
17505ea5d9 LibGUI: Ensure that edit actions are disabled for password boxes
This ensures that the user can't copy/cut text from password boxes which
would reveal the password. It also makes sure that the undo/redo actions
stay disabled because it's difficult to reason about what these do
exactly without being able to see the result.
2021-08-02 12:48:55 +01:00
Gunnar Beutner
9179d01915 LibGUI: Remove redundant code 2021-08-02 12:48:55 +01:00
TheFightingCatfish
0c53c2dfa2 LibGUI: Add a ClipboardClient for GUI::Clipboard
Anyone who inherits from `GUI::Clipboard::ClipboardClient` will receive
clipboard notifications via `clipboard_content_did_change()`.

Update ClipboardHistoryModel, TextEditor and TerminalWidget to inherit
from this class.
2021-07-27 23:49:25 +02:00
TheFightingCatfish
9b78ae5149 LibGUI+Browser: Do not paste bitmaps
This prevents GUI::TextBox and the `Paste & Go` action in the browser
from trying to paste a bitmap. Also, the paste action is enabled
and disabled on clipboard change to reflect if the clipboard data
can be pasted.
2021-07-25 12:36:23 +02:00
Andreas Kling
c7d891765c LibGfx: Use "try_" prefix for static factory functions
Also mark them as [[nodiscard]].
2021-07-21 18:02:15 +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
Hendiadyoin1
ed46d52252 Everywhere: Use AK/Math.h if applicable
AK's version should see better inlining behaviors, than the LibM one.
We avoid mixed usage for now though.

Also clean up some stale math includes and improper floatingpoint usage.
2021-07-19 16:34:21 +04:30
Timothy
73226a2861 LibGUI: Convert TextEditor to east-const style 2021-07-10 15:33:46 +02:00
Timothy
73ae5200a9 TextEditor+LibGUI: Use unveil and FileSystemAccessServer
Making use of the new FileSystemAccessServer we are able to use
unveil without restricting our ability to open and save files.
A file argument will be unveiled automatically however all other files
require user action via the FileSystemAccessServer to gain access.
2021-07-10 15:33:46 +02:00
networkException
f8798c154b LibGUI: Draw the placeholder of a TextEditor also when it is focused
Previously focusing a TextEditor would cause the placeholder to
disapper. This is unpractical editors that get focused automatically
for example.
2021-07-07 15:29:03 +02:00
Marcus Nilsson
2264de9921 LibGUI/TextEditor: Set cut and copy actions to disabled on init
We can presume that there is nothing to cut or copy on init since
nothing is selected yet.
2021-07-03 17:36:50 +02:00
Max Wipfli
de67d86696 LibGUI: Add glyph substitution to TextEditor
This patch adds the member variable m_substitution_code_point to
GUI::TextEditor. If non-zero, all gylphs to be drawn will be substituted
with the specified code point. This is mainly needed to support a
PasswordBox.

While the primary use-case is for single-line editors, multi-line
editors are also supported.

To prevent repeated String construction, a m_substitution_string_data
members has been added, which is an OwnPtr<Vector<u32>>. This is used as
a UTF-32 string builder. The substitution_code_point_view method uses
that Vector to provide a Utf32View of the specified length.
2021-06-30 11:12:25 +02:00
Max Wipfli
37961bf7cb LibGUI: Fix double-clicking words in syntax-highlighted text
This patch fixes a bug where double-clicking on a word in a TextEditor
with syntax highlighting would also select an additional character after
the word. This also simplifies the logic for double- and
triple-clicking.
2021-06-30 11:12:25 +02:00
Andreas Kling
bec2b3086c LibGUI: Don't fire on_change hook at start of TextEditor::paint_event()
If something happens in response to on_change that causes the widget
to get unparented, creating a GUI::Painter will fail since it can't
find the window to paint into.

Since painting only cares about the syntax highlighting spans, what we
really want is to ensure that spans are up-to-date before we start
painting.

The problem was that rehighlighting and the on_change hook were bundled
together in an awkward lazy update mechanism. This patch fixes that by
decoupling rehighlighting and on_change. Rehighlighting is now lazy
and only happens when we handle either paint or mouse events. :^)

Fixes #8302.
2021-06-29 11:22:57 +02:00
Dmitrii Ubskii
8501617fcb LibGUI+HackStudio: Make gutter a first class element
Gutter -- a space left of the text, before the ruler -- is not a part of
the ruler, nor should it be treated as such. This commit implements
gutter handling in LibGUI::TextEditor as part of mild cleaning up of the
gutter handling (breakpoint icons) in HackStudio's Editor.

This commit also enables separate theming of the gutter.
2021-06-13 12:33:15 +01:00
Sreelakshmi
a471af4ae1 TextEditor: Don't close autocomplete box or stop timer on leave_event
The autocomplete box closes on its own when the user tries to hover
over it because text_editor consideres hovering over the box to be
a leave_event. This commit stops that from happening.
2021-06-12 23:54:08 +04:30
Sam Atkins
6f92d1e639 LibGUI: Set TextEditor to unmodified after saving size=0 files
This fixes #7946

Previously, TextEditor::write_to_file() would not mark its document
as unmodified if the file size was 0. This caused a desync in the
Text Editor app between the window's is_modified state and the
TextEditor's. It's already noted in the comments of the app's
save action code that propagating the modified state automatically
would be good, and it would solve issues like this, but I'm not yet
familiar enough with the code to try a change like that.
2021-06-09 18:53:13 +02:00
Max Wipfli
a819f98956 LibGUI: Fix off-by-one error in rendering of highlighted text
This fixes an off-by-one error in TextEditor's rendering of the syntax
highlighting as generated by Syntax::Highlighter and its subclasses.

Before, a single character span was e.g. (0-3) to (0-3), but this was
considered invalid by GUI::TextRange. Now, a single character span would
be e.g. (0-3) to (0-4).

This fix requires all Syntax::Highlighter subclasses to be adjusted, as
they all relied on the previous implementation. This will then also fix
a bug where single-character HTML tags wouldn't be highlighted.
2021-06-05 00:32:28 +04:30