Commit Graph

287 Commits

Author SHA1 Message Date
Nathan Sobo
c626836b2e Only clear linesToMeasure when we have actually measured
Previously, as soon as we decided to render linesToMeasure, we would
clear them out. However, if a second update interleaved with the update
that initially requested measurement, it could cause the requested lines
to not be present when the measurement phase from the first update
occurred. Now, any additional updates will only add to the set of lines
that need to be measured until the measurement phase actually happens.

Signed-off-by: Antonio Scandurra <as-cii@github.com>
2017-08-16 11:28:58 -06:00
Nathan Sobo
e9a00ce9b3 Merge pull request #15324 from atom/ns-fix-mousewheel-handling
Only scroll one axis at a time, whichever has the greater delta
2017-08-15 19:29:36 -06:00
Nathan Sobo
4493ae2270 Only scroll one axis at a time, whichever has the greater delta 2017-08-15 16:08:07 -06:00
Nathan Sobo
c9b558a08a Move placeholder text inside .lines div
If themes apply padding to the .lines div, the placeholder text looks
mis-aligned unless it is placed within the .lines div
2017-08-15 15:38:04 -06:00
Nathan Sobo
586b818bae Merge pull request #15317 from atom/as-fix-wrong-measurements
Move cursors container inside lines container
2017-08-15 11:38:54 -06:00
Antonio Scandurra
3d71e627eb Move cursors container inside lines container
This will ensure that applying any style that changes the location of
the lines container will also correctly position the cursors.
2017-08-15 18:44:23 +02:00
Nathan Sobo
360f89e33a Merge pull request #15314 from atom/as-stop-ime-input-on-prevent-default
Suppress text input for default-prevented keydown events
2017-08-15 10:13:40 -06:00
Nathan Sobo
7226f6fb08 Merge pull request #15313 from atom/as-fix-extra-schedule-update
Ensure extra document updates are not scheduled during `updateSync`
2017-08-15 09:01:22 -06:00
Antonio Scandurra
37274d3365 Suppress text input for default-prevented keydown events
This is a continuation of #15266. In that pull-request we managed to
prevent IME previews from being displayed in the editor when the
originating `keydown` event was default-prevented. However, it was still
possible for IME input to make it through the previous workarounds, thus
triggering the `textInput` event and showing unwanted text.

Pressing another key that would complete the in-progress IME input
would, in fact, first replace `this.lastKeydown` and then trigger the
`textInput` event. In the handling of that event we would detect
`this.lastKeydown` as "non-default-prevented" and therefore mistakenly
insert the IME text.

With this commit we are adopting a different strategy to mitigate the
issue. When receiving the wrong `compositionupdate` event we will first
disable the hidden input and then re-enable it on the next tick.
Disabling the input causes the in-progress IME input to be aborted and
the browser to never fire `textInput` nor `compositionupdate` events
anymore after that.

The only downside of this approach is that the hidden input also loses
focus, but we transfer it back to it as soon as the next tick of the
event loop is served and the input has been re-enabled.
2017-08-15 16:44:53 +02:00
Antonio Scandurra
f569514938 Ensure extra document updates are not scheduled during updateSync
When changing the editor styles, we force the component to remeasure
character dimensions. If they change, each line's height could change
too, causing the current scroll top position to not match the viewport
the user was observing. Thus, when detecting a line height change, we
try to show users the area of the screen they were looking prior to
tweaking the font size.

In trying to maintain the aforementioned logical position, however, we
were mistakenly scheduling a new update before actually finishing the
current one. This was problematic because if the first update detected
that the longest screen line changed and such line was off-screen, it
would try to render it. Before having the chance to measure it, though,
the new update would kick in and delete the new longest screen line
node, because it assumed it had already been measured. Finally, when
`measureContentDuringUpdateSync` fired, it would notice that the longest
screen line node did not exist and throw an exception as a result.

This commit changes the `updateSync` method to set the `updateScheduled`
flag only before returning control to the caller, as opposed to doing so
at the beginning. This prevents calls to `scheduleUpdate` made in
`updateSync` from scheduling new unwanted updates.
2017-08-15 15:32:29 +02:00
Antonio Scandurra
e980598aba Honor editor's scrollSensitivity parameter 2017-08-15 12:22:59 +02:00
Nathan Sobo
433c514673 Always render hidden input
This avoids mysterious timing issues in which the editor gets a 'focus'
event in a state where `isVisible` returns false. If we always render
the hidden input, we can always focus it.

Signed-off-by: Antonio Scandurra <as-cii@github.com>
2017-08-14 11:53:02 -06:00
Antonio Scandurra
eb1eeb3fde Ignore clicks on block decorations
Previously, clicking on a block decoration to interact with it would
cause the editor to scroll to the line next to it. This is inconvenient,
especially if the decoration was designed to be interactive and
contained buttons or links. If the decoration was close to the bottom of
the screen, clicking on a button inside of it would make the editor
scroll down and abort the click.

This behavior regressed during the editor rendering layer rewrite and
with this commit we are restoring the original behavior by simply
ignoring clicks that land on block decorations.
2017-08-14 15:43:48 +02:00
Nathan Sobo
38978da0fa Explicitly compare compositionCheckpoint against null, since it can be 0 2017-08-13 14:03:58 -06:00
Nathan Sobo
744b96df46 Suppress composition events default prevented on previous keydown
This seems like a browser bug.
2017-08-12 13:50:08 -06:00
Nathan Sobo
ff32fd80bf Merge pull request #15273 from atom/as-fix-line-height-0
Don't throw an error when setting an incredibly small `lineHeight`
2017-08-12 13:46:23 -06:00
Nathan Sobo
d8a8b03db2 Merge pull request #15275 from atom/as-fix-scrollbar-cursor
Use default cursor on dummy scrollbars and make them 15px wide/tall
2017-08-12 13:30:41 -06:00
Nathan Sobo
feb0cddf5e Merge pull request #15265 from atom/ns-ime-workaround
Work around incorrect data on `compositionupdate` events in Chrome 56
2017-08-12 13:26:01 -06:00
Antonio Scandurra
8cbfcf6e2b Use default cursor on dummy scrollbars and make them 15px wide/tall 2017-08-12 15:56:19 +02:00
Antonio Scandurra
964f209c40 Don't throw an error when setting an incredibly small lineHeight
Instead, if the measured line height equals 0, default it to 1 so that
the editor component doesn't start computing `NaN` or `Infinity` values
due to e.g. dividing by 0.

We should probably consider sanitizing line heights smaller than a
certain threshold, but that's non trivial because line height is
expressed as a multiplier of the font size. Also, users may style the
`line-height` property via CSS, which may still throw errors when using
small values.
2017-08-12 15:38:32 +02:00
Antonio Scandurra
b4f029e9f0 Test both Chrome 56 and other Chrome versions IME behavior 2017-08-12 14:38:18 +02:00
Antonio Scandurra
fc1327eb22 Fix measuring lines in presence of pending autoscroll requests
Calling `pixelPositionForScreenPosition` was sometimes throwing an error
indicating that the requested position was not rendered and that, as
such, could not be measured.

This was caused by trying to measure a line that was visible at the
moment of the call while also having a pending autoscroll request that
would cause that line to go off-screen. Due to how the code was
structured, we would mistakenly detect that line as visible, autoscroll
to a different location, re-render a different region of the buffer and
then try to measure the now invisible line.

This commit fixes this issue by restructuring and simplifying the logic
for rendering extra lines in order to measure them. Now, every line for
which a measurement has been requested is stored in a `linesToMeasure`
map. During the first phase of the update process (after honoring
autoscroll requests), we detect which of these lines are currently
visible and if they're not, store them into the
`extraRenderedScreenLines` map, which is then used to render lines that
are invisible but need to be measured.
2017-08-12 12:31:50 +02:00
Antonio Scandurra
ca183dd693 Don't insert IME preview on next tick if composition has already ended 2017-08-12 10:06:56 +02:00
Nathan Sobo
54a6f0d29f Clear hidden input compositionstart on Chrome 56
We use the value of the hidden input to display a preview of the
composition, but it might already contain spaces from previous
keystrokes, since we don't call preventDefault when spaces are inserted.
2017-08-11 15:57:46 -06:00
Nathan Sobo
8667cfdd13 Work around incorrect data on compositionupdate events in Chrome 56 2017-08-11 15:47:37 -06:00
Antonio Scandurra
00d27befe8 Create, update and destroy highlights manually
Etch's reconciliation routine causes elements to be sometimes
re-ordered. In order to move an element, however, Etch needs to first
detach it from the DOM and then re-append it at the right location.

This behavior is unacceptable for highlight decorations because it could
re-start CSS animations on a certain highlight decoration when a
completely different one is added or removed.

Even though we are still interested in restructuring etch's
reconciliation logic to prevent unwanted re-orderings, with this commit
we are switching to a custom routine to create/update/remove highlight
decorations that prevents unnecessary moves and, as a result, fixes the
undesired behavior described above.
2017-08-10 17:48:34 +02:00
Jason Rudolph
3dc2e61990 Add comment explaining motivation for didPaste implemenation 2017-08-07 12:43:13 -04:00
Jason Rudolph
b9ace6a5b6 🎨 2017-08-07 12:31:04 -04:00
Jason Rudolph
c7bfbc181c 🐛 Fix atom/tabs#461
On Linux, when the user performs a middle-button mouse click, Chromium
fires both a mouse-down event *and* a paste event. This commit teaches
the TextEditorComponent to ignore the paste event.

When the user performs a middle-mouse click on a tab, we get close the
tab and attempt to prevent Chromium's default processing for the event.
[1] This prevents Chromium's default processing for the *mouse down*
event, but then Chromium also fires a *paste* event, and that event
pastes the clipboard's current content into the newly-focused text
editor. 🙀

Since Atom already has its own logic for handling pasting, we
shouldn't (🤞) need to handle browser paste events. By ignoring the
browser paste events on Linux, we fix atom/tabs#461.

[1]
ce1d92e0ab/lib/tab-bar-view.coffee (L416-L418)
2017-08-07 10:19:08 -04:00
Nathan Sobo
1584189962 Ensure custom decoration elements fill their container 2017-08-02 20:34:18 -06:00
Max Brunsfeld
48abb16edb Fix exception in screenPositionForPixelPosition when content updates are pending
Signed-off-by: Nathan Sobo <nathan@github.com>
2017-07-18 14:31:47 -07:00
Bryant Ung
c50f73e9f5 Merge pull request #15011 from mehcode/gutter-marker-layer-bug
Check if incoming element is non-null before attempting to append to it
2017-07-13 22:29:44 -07:00
Antonio Scandurra
c3f7edc104 Swap underlying editor correctly when calling setModel on editor element
Previously, when `setModel` was called, we forgot to update the pointer
to the component in the newly supplied editor. This was causing the
element to not update in response to model updates but only as a result
of focus or visibility changes. We suspect this regressed during the
rewrite of the editor rendering layer.

With this commit we will now correctly swap the element's underlying
editor by updating the component pointer on the newly supplied editor.
Also, if the element was already attached to another editor, we will
null out the component reference on it, because one instance of
`TextEditorElement` can only represent one instance of `TextEditor`.
2017-07-13 18:13:48 +02:00
Ryan Leckey
d0588cd812 Check if incoming element is non-null before attempting to append to it 2017-07-13 02:32:43 -07:00
ungb
07c7e53b1e fix lint errors 2017-07-10 16:26:47 -07:00
Nathan Sobo
f6d2f966bf Fix middle-mouse-button paste on Linux
Chrome now synthesizes a textInput event on mouseup for middle mouse
button clicks, which rendered our custom JS for handling that case
redundant.
2017-07-10 15:53:23 -06:00
Nathan Sobo
cd27b49dc4 Don't handle ctrl-click events on macOS
It brings up the context menu, so we shouldn't change the cursor
position
2017-07-10 14:28:21 -06:00
Nathan Sobo
82619a989b 🎨 2017-07-10 14:27:55 -06:00
Nathan Sobo
960e515e77 Merge pull request #14948 from atom/ns-add-gutter-decoration-class
Always render 'decoration' class on custom decorations
2017-07-05 15:24:43 -06:00
Antonio Scandurra
bcaf655325 Update buffer-row and screen-row data fields on each line number node 2017-07-05 11:12:48 +02:00
Antonio Scandurra
942dd03bd0 Assign screen-row to each line number as a data field 2017-07-05 11:11:44 +02:00
Nathan Sobo
e7b4ad48f0 Always render 'decoration' class on custom decorations 2017-07-03 16:10:41 -06:00
Antonio Scandurra
b30f55bb57 Invalidate block decorations height automatically if their size changes 2017-06-30 14:08:49 +02:00
Antonio Scandurra
57570accbf Merge pull request #14893 from atom/as-fix-resetting-node-pool-styles
Fix resetting styles in NodePool
2017-06-27 11:35:19 +02:00
Antonio Scandurra
52ba6c7342 Fix measuring block dec. if adding them before updating element's width 2017-06-26 12:52:18 +02:00
Antonio Scandurra
a171380544 Fix resetting styles in NodePool
Previously, we were mistakenly not clearing out some styling properties
like `marginTop`, thus causing e.g. line numbers to be misaligned. This
was caused by manual updates to an element's style object, without a
consequent update to the NodePool.

With this commit we will now rely on `element.styleMap` (a DOM
primitive) to detect which styles have been set on a element that is
about to be recycled and, if the object being created doesn't use them,
simply clear them out.
2017-06-26 11:37:11 +02:00
Antonio Scandurra
0a46c9ad7b Prevent block decorations from mistakenly wrapping during measurements
Before rendering block decorations, we read their heights by putting
them into a special div called `blockDecorationMeasurementsArea`.

Previously, this div was not explicitly sized, which was causing
decorations to wrap while being measured but not when actually rendering
them.

This commit fixes this inconsistency by explicitly styling the
measurement area so that it has the same width as the component scroll
width.
2017-06-13 12:31:27 +02:00
Antonio Scandurra
9a0709e95e Don't try to measure lines that don't exist
By the time that the animation frame is delivered, the requested
autoscroll
position could not exist anymore. This could cause the editor component
to measure a non-existent line and, as a result, throw an exception.

With this commit we will always ignore measurements for screen lines
that do not exist.
2017-06-09 18:40:24 +02:00
Antonio Scandurra
baca845e64 Fix not resetting unused styles in NodePool 2017-06-03 14:56:21 +02:00
Antonio Scandurra
ec774e143a Fix lint errors 2017-06-03 10:52:32 +02:00