Commit graph

123 commits

Author SHA1 Message Date
offtkp
62d41d58d6 LibGUI: Consider TextEditor icon size when scrolling text horizontally
If an icon exists and the horizontal scroll value is larger than 0,
translate the TextEditor painter by the icon size and padding.

The text would scroll over the icon when the text was long enough to
trigger a horizontal scroll.

Fixes #13669.
2022-05-09 22:52:05 +02:00
faxe1008
448d6b9acc LibGUI: Make TextEditor substitution more explicit
This patch changes the member for the code point substitution to be an
Optional to remove the implicitness of the zero value.
2022-05-08 16:36:53 +02:00
Lucas CHOLLET
86d4b7ebfc LibGUI: Display line number next to the first visual line
The number was previously vertically centered, but it prevents from
quickly seeing a line change.
2022-04-25 10:46:58 +02:00
Lucas CHOLLET
881f499704 LibGUI: Fix text wrap artifact when selecting text
The issue was caused by the usage of the
selection_end_column_within_line variable as if it was the visual line.
This is fixed by taking the minimum between this value and the length of
a visual line.
2022-04-24 19:14:28 +02:00
SimonFJ20
791e881892 LibGUI: Rename function to make intention clearer 2022-04-13 21:24:48 +02:00
SimonFJ20
661e7d691e LibGUI+GMLPlayground: Replace text using ReplaceAllTextCommand 2022-04-13 21:24:48 +02:00
Simon Wanner
206d6ece55 LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
Itamar
5f2a0f03a6 LibGUI: Add search API to TextEditor with highlighted results
This adds a search API to TextEditor.

The API that is similar to "find_text" of TextDocument (which is used
internally to do the search).

All search results (as well as the current one) are highlighted with
a "span collection", which is pretty neat :^)
2022-03-29 17:45:36 +02:00
Itamar
ab0b4f46f7 LibGUI: Support multiple layers of TextDocument spans
TextDocument::set_spans() now also takes a "span collection index"
argument.

TextDocument keeps a map between a span collection index and its spans.
It merges the spans from all collections into a single set of spans
whenever set_spans() is called.

This allows us to style a document with multiple layers of spans, where
as previously we only supported a single layer of spans that was set
from the SyntaxHighlighter.
2022-03-29 17:45:36 +02:00
Rok Povsic
7da0d94d03 LibGUI: Add CTRL+Enter callback to TextEditor 2022-03-22 12:17:48 +01:00
Lucas CHOLLET
1172fd682a TextEditor: Support multiline highlighting for trailing space
The last commit fixes a bug, but also exposes the fact that trailing
space highlighting isn't really supported on multiple lines. This patch
correct the wrong behavior by adding an offset to adjust rectangle's
position.
2022-02-28 14:00:27 +01:00
Lucas CHOLLET
9c2e89e8b8 TextEditor: Fix highlighting bug in wrapping mode
Before this patch the highlighted rectangle wasn't placed on the right
spot. Now the red highlighting is correctly placed at the end of the
line. This was due to a function called with a wrong argument.
2022-02-28 14:00:27 +01:00
thankyouverycool
5fedb742da LibGUI: Set Editors to wrap at words when MultiLine
And default to NoWrap when they are type SingleLine.
2022-02-26 22:54:25 +01:00
thankyouverycool
94b74937d8 LibGUI+LibSyntax: Stringify Highlighter::Language
This patch adds a Highlighter::Language -> string helper and a
callback for Highlighter changes.
2022-02-24 19:09:41 +01:00
thankyouverycool
d94db1900e LibGUI+LibGfx: Defer to fonts when setting Editor line height
Fonts now provide their preferred line height based on maximum
height and requested line gap. TTFs provide a preferred line gap
from table metrics while BitmapFonts are hardcoded at the previous
default for now.
2022-02-24 18:09:22 +01:00
thankyouverycool
07910c12e3 LibGUI: Ensure ruler grows properly when using proportional fonts
Ruler needs to take into account spacing between glyphs for
proportional fonts as line count increases. This also replaces
the less accurate 'x' width estimate for widest character with
a '4'
2022-02-24 18:09:22 +01:00
Sam Atkins
decdd6b61a LibGUI: Add missing LibCore/File include
This was previously included via ConfigFile.h
2022-02-16 19:49:41 -05:00
electrikmilk
3c11dc5bd3 Base+HackStudio: Add or insert missing icons
Insert or add icons where they are missing.
2022-02-10 10:27:26 +00:00
Itamar
10d75d7f21 LibGUI: Add TextEditor::force_rehighlight() method 2022-02-09 00:51:31 +01:00
thankyouverycool
6f37351142 LibGUI: Simplify DisplayOnly painting for TextEditor 2022-02-07 15:05:22 +00:00
thankyouverycool
2c1a417513 LibGUI: Fix typo in TextEditor::paint_event 2022-02-07 15:05:22 +00:00
thankyouverycool
f35a6c13ab LibGUI+TextEditor: Highlight the entire current line
And fix Line Highlighting's duplicate alt-menu shortcut.

Previously only text on the cursor's line was highlighted. This makes
discerning cursor focus on empty lines easier.
2022-02-07 15:05:22 +00:00
thankyouverycool
b2df863b55 LibGUI: Adjust TextEditor's clipping rect for text
And simplify its construction.

The first visual line was being over-clipped vertically by an amount
equal to the frame's thickness. Selections and icons in TextBoxes and
the first line of Editors now display correctly.
2022-02-07 15:05:22 +00:00
thankyouverycool
2424858c32 LibGUI: Register gutter and ruler GML properties for TextEditor 2022-02-07 15:05:22 +00:00
Andreas Kling
1b9e98a17d LibGUI: Paint GUI::TextEditor's optional icon before applying text clip
We were chopping the top row of pixels off of the website favicons in
Browser's location editor. :^)
2022-02-07 12:25:25 +01:00
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