Commit graph

88 commits

Author SHA1 Message Date
Zac
6a569bbdd7 TextEditor: Change cursor behaviour when clicking empty space
When clicking empty space (beneath any used lines) in the TextEditor,
the cursor would jump to the start of the last line, rather than the
correct column, or the end of the line where appropriate. This was
because in the for_each_visual_line callback would return
IterationDecision::Continue if the clicked point wasn't in the line's
rect. Thus the callback would continue on each iteration and at the
end, would set the cursor to the default column of 0. To fix this I
added a bool to the callback's signature which tells the callback if
the for_each_visual_line method is on the last visual line. The
callback now does not return IterationDecision:Continue if
for_each_visual_line method is on the last line and the correct column
is then calculated with the line passed.
2020-11-19 21:59:13 +01:00
Jack Byrne
1041ab88ca
TextEditor: Go-to-line now shows line in middle of view (#4008) 2020-11-10 09:53:50 +01:00
Andreas Kling
982e066100 LibGfx: Move FontDatabase from LibGUI to LibGfx
Not sure why I put this into LibGUI in the first place.
2020-10-31 13:56:21 +01:00
Andreas Kling
aef56159a8 LibGUI: Add Widget focus policies
Every widget now has a GUI::FocusPolicy that determines how it can
receive focus:

- NoFocus: The widget is not focusable (default)
- TabFocus: The widget can be focused using the tab key.
- ClickFocus: The widget can be focused by clicking on it.
- StrongFocus: Both of the above.

For widgets that have a focus proxy, getting/setting the focus policy
will affect the proxy instead.
2020-10-30 17:03:28 +01:00
Andreas Kling
f57c058c5e LibGUI: Call up to the correct base class in GUI::TextEditor 2020-10-26 21:01:45 +01:00
Andreas Kling
1d96ecf148 Everywhere: Add missing <AK/TemporaryChange.h> includes
Don't rely on HashTable.h pulling this in.
2020-10-15 23:49:53 +02:00
Nico Weber
397e5766ff LibGUI: Make arrow-left/right with selection move cursor to edge of selection
This matches behavior on Linux, macOS, Windows, and it makes it possible
to hit ctrl-L arrow-right ctrl-backspace to edit the last component of
an URL in browser, or of the current path in File Manager.

Also make it so that ctrl-left/right does a word movement that starts
at the edge of the selection. This matches Linux and macOS, but not
Windows (which instead does a word movement relative to the cursor,
not the selection edge).
2020-10-08 23:22:30 +02:00
Itamar
863f14788f HackStudio: Add C++ Language Server
The language server keeps track of the content of currently edited
files by receiving updates about edit actions.

Also, C++ autocompletion is no longer tied to HackStudio itself and
moved to be part of the language server.
2020-09-30 21:46:59 +02:00
Ben Wiederhake
08f9bc26a6 Meta+LibHTTP through LibWeb: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Andreas Kling
468a29f4a1 LibGUI: Register the "text" property on GUI::TextEditor 2020-09-25 20:43:35 +02:00
Peter Elliott
253ab7536a Base: Add the PlaceholderText attribute to themes 2020-09-21 20:15:10 +02:00
Peter Elliott
fa96e57c15 LibGUI: Add optional placeholder to TextEditor
This lets you show some disabled text when no text is entered, and the
editor is not focused.
2020-09-21 20:15:10 +02:00
Andreas Kling
7a2faecc15 LibGUI: Use widget override cursors in GUI::TextEditor 2020-09-11 14:26:37 +02:00
Andreas Kling
b4f307f982 LibGUI+WindowServer: Rename window "override cursor" to just "cursor"
Let's just say each window has a cursor, there's not really overriding
going on.
2020-09-11 14:26:37 +02:00
Andreas Kling
0f9be82826 LibGfx: Move StandardCursor enum to LibGfx
This enum existed both in LibGUI and WindowServer which was silly and
error-prone.
2020-09-10 19:25:13 +02:00
Andreas Kling
51146e3075 LibGUI: Make the Clipboard API deal in raw byte buffers a bit more
To open up for putting not just text/plain content on the clipboard,
let's make the GUI::Clipboard API a bit more raw-data-friendly. :^)
2020-09-05 16:16:01 +02:00
Andreas Kling
dec3998b3c LibGUI: Disable whitespace visualization in single-line text editors
You can enable it manually if you really want it, of course. :^)
2020-09-01 23:57:30 +02:00
Andreas Kling
aa70d8c217 LibGUI: Implement trailing whitespace visualization in TextEditor
This patch adds an optional mode where TextEditor highlights trailing
whitespace characters on each line with a nice reddish dither pattern.

We should probably make this themable and I'm sure it could be nicer
somehow, but this is just a first cut and I do kinda like it. :^)
2020-09-01 23:55:35 +02:00
Itamar
ebab512c03 TextEditor: Increase padding in ruler width 2020-08-22 09:48:59 +02:00
thankyouverycool
bc27aa9b6f LibGUI: Use matching family fonts for TextEditor ruler
Fixes incorrect glyph sizes when drawing bold line counts.
2020-08-16 19:39:46 +02:00
thankyouverycool
a5fefbf840 LibGUI: Resize TextEditor ruler based on needed space
Ruler width is now calculated according to the number of digits
in the line count.
2020-08-16 19:39:46 +02:00
Andreas Kling
c1e0047b48 LibGUI: When focusing a TextEditor via keyboard, select all contents
This feels very natural and allows you to start typing immediately
knowing it will replace whatever was in the text box before.
2020-08-15 00:05:45 +02:00
Andreas Kling
75b8f4e4e6 LibGUI: Make focus events more aware of why focus is changing
This patch adds GUI::FocusEvent which has a GUI::FocusSource.
The focus source is one of three things:

- Programmatic
- Mouse
- Keyboard

This allows receivers of focus events to implement different behaviors
depending on how they receive/lose focus.
2020-08-15 00:05:45 +02:00
Ben Wiederhake
1396ce8a9b LibGUI: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code.
2020-08-12 20:40:59 +02:00
Nico Weber
ce95628b7f Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:

    git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05 22:33:42 +02:00
Nico Weber
19ac1f6368 Revert "Unicode: s/codepoint/code_point/g"
This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
2020-08-05 22:33:42 +02:00
Linus Groh
9ef834384d LibGUI: Use set_cursor() in TextEditor::set_document()
Instead of setting m_cursor directly to reset the cursor position,
TextEditor::set_document() now uses set_cursor() which will call cursor
change callback functions, if any.

This fixes a bug in HackStudio where the cursor information text would
not update immediately after changing the active TextDocument, even
though the cursor is always visibly being reset to 0, 0.
2020-08-05 17:27:14 +02:00
Andreas Kling
ea9ac3155d Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
2020-08-03 19:06:41 +02:00
AnotherTest
c35493c156 LibGUI: Add focus hooks to TextEditor 2020-08-01 08:39:26 +02:00
Sasan Hezarkhani
a2bbacbfc8 TextEditor: Jump to word break when deleting and holding Ctrl modifier 2020-07-23 13:08:55 +02:00
Tom
65a11fb5f9 LibGUI: Add InputBox::show with required parent window argument
Similar to MessageBox::show, this encourages passing in a window.
2020-07-16 16:10:21 +02:00
thankyouverycool
a038f82326 LibGUI: Disallow typing in DisplayOnly TextEditors 2020-07-16 00:06:18 +02:00
thankyouverycool
6a78db07f1 LibGUI: Add hover highlighting and keyboard controls to ComboBox
Adds a new highlighting effect to the actively selected row in
ComboBox ListView. ComboBoxEditor can now be controlled with
page up, page down, and the up and down arrow keys. ESC and loss
of focus now cause comboboxes to close. Now activates on mouseup
as well as return.
2020-07-15 13:19:44 +02:00
thankyouverycool
b2783a234a LibGUI: Use enum for TextEditor modes & add new DisplayOnly mode
Adds a new, more restrictive read-only state to TextEditor which
forbids copying, selecting, editor cursors, and context menus.
Provides a unique appearance on focus which accomodates ComboBox
widgets. All TextEditor modes are now accessed by enum and
set_mode() which sets the editor to Editable, ReadOnly or
DisplayOnly. Updates applications still using set_readonly().
2020-07-15 13:19:44 +02:00
Andreas Kling
d851863704 Userspace: Remove a bunch of unnecessary Kernel/API/KeyCode.h includes 2020-07-04 17:25:31 +02:00
Andreas Kling
11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
Andreas Kling
eec22acb8e LibGUI: Add GUI::CommonActions::make_select_all_action() :^) 2020-07-03 21:34:12 +02:00
Andreas Kling
f50bc0f314 LibGUI: Add TextEditor::set_icon()
You can now set a 16x16 icon on a single-line TextEditor. If present,
the icon will be painted to the left of the text content.
2020-06-29 20:34:42 +02:00
Hüseyin ASLITÜRK
53227f400c LibGUI: Replace text attribute on KeyEvent with code_point attribute 2020-06-16 13:15:17 +02:00
Kevin Meyer
17aa917073 LibGUI: Don't update cursor, if visual data out-of-date
This fixes https://github.com/SerenityOS/serenity/issues/2498
A nullptr dereference was caused by the visual data beeing out of sync
with the line data, due to a deferred recompute.
2020-06-15 22:32:18 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Andreas Kling
116cf92156 LibGfx: Rename Rect,Point,Size => IntRect,IntPoint,IntSize
This fits nicer with FloatRect,FloatPoint,FloatSize and gives a much
better visual clue about what type of metric is being used.
2020-06-10 10:59:04 +02:00
Andreas Kling
b81b2a85c4 LibGUI: Don't scroll cursor into view while reflows are deferred
We don't have up-to-date visual line rects until after reflow, and we
already do a "scroll cursor into view" when deferral ends anyway.

Fixes #2524.
2020-06-07 21:05:05 +02:00
Andreas Kling
984a6ff97b LibGUI: Fix broken clip rect when scrolling a TextEditor 2020-06-07 18:02:43 +02:00
Andreas Kling
5c485d4a1e LibGUI: Fix TextEditor painting glitch after add_clip_rect() change 2020-06-06 19:37:03 +02:00
FalseHonesty
061938206a LibGUI: Fix cursor being out of view after typing
Previously, if the cursor moved out of the visible area while text
was being inserted, the text editor would never scroll the cursor
back into view until the arrow keys were pressed to move the cursor.
This was caused by the TextEditor's reflow deferral system stopping
visual line recomputation until the end of text insertion, so now
when reflow deferral is completed, the TextEditor will make sure
the cursor is visible.
2020-05-29 22:14:45 +02:00
FalseHonesty
b0b03c52af LibGUI: Fix TextEditor crashing when selecting a blank line
Previously, the TextEditor would crash when selecting a line with
no codepoints due to a null dereference, so this patch makes sure
there is actually any text to render before giving it to the painter.
2020-05-29 20:17:53 +02:00
Andreas Kling
a8f0e4d56e LibGUI: Defer line reflow during text insertion
Add a deferral counter and defer reflowing the visual lines until the
counter is at zero. Use this to defer reflow when inserting text.

This fixes glacial slowdown while paste large amounts of text.
2020-05-27 19:52:18 +02:00
Andreas Kling
30edd198ec LibGUI: Make TextEditor::select_all() move the cursor to document head
This feels a lot nicer than moving the cursor to the document end.
2020-05-27 19:52:18 +02:00
FalseHonesty
4ad891a078 LibGUI: Add flag to TextDocument's word break locator methods
TextDocument::first_word_break_before was refactored out to be able
to be used in multiple places throughout the project. It turns out
that its behaviour needs to be slightly different depending on
where its called, so it now has a start_at_column_before flag
to decide which letter it "thinks" was clicked.
2020-05-25 11:33:39 +02:00