-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACE line heights since 1.13.1 #5012
Comments
@andredcoliveira could you please take a look? |
v1.13.1 did change the way line heights (and widths) are calculated via commit e57a9d9—which happens here. Before: this.$measureSizes = function(node) {
var size = {
height: (node || this.$measureNode).clientHeight,
width: (node || this.$measureNode).clientWidth / CHAR_COUNT
};
// Size and width can be null if the editor is not visible or
// detached from the document
if (size.width === 0 || size.height === 0)
return null;
return size;
}; After: this.$measureSizes = function(node) {
node = node || this.$measureNode;
// Avoid `Element.clientWidth` since it is rounded to an integer (see
// https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth).
// Using it here can result in a noticeable cursor offset for long lines.
const rect = node.getBoundingClientRect();
const charSize = {
height: rect.height,
width: rect.width / this.charCount
};
// Size and width can be null if the editor is not visible or
// detached from the document
if (charSize.width === 0 || charSize.height === 0)
return null;
return charSize;
}; This change was made because So, I do see a change in line heights by using the Vue snippet you provided and switching between
As a side note, I changed the following line in your snippet: this.editor.setValue(this.definition) // this.definition is `undefined` to: this.editor.setValue('THESE\nARE\nSOME\nRANDOM\nWORDS') Even without fully understanding the root cause, I can think of 2 potential mitigations:
|
@jmthomas To clarify, have you confirmed that your reproduction snippet does reproduce the issue? Double checking since the screenshot you provided is not what the snippet results in. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
@andredcoliveira I can consistently reproduce this in our application where we pop open an edit dialog. What's interesting is that our script editor application doesn't experience this issue. If I change the page zoom level it regenerates the editor with the correct heights so this is something that's happening on initial render. I'll play with it some more but I don't know how to override internal Ace methods in my application so I'm simply observing behavior. |
I can confirm adding a small delay |
@Tiuipuv The odd highlight is because Ace miscalculated the width as well as the height. I saw something similar where I couldn't move the cursor past the end of the line and editing was really weird. |
@jmthomas Yeah I was figuring that may be the case. the reason I included it was because I was worried about @andredcoliveira's potential solution of:
This made me wonder if it would then highlight with the same oddity horizontally, but be fixed vertically. But who knows, I know very little about ace's code base. for now :) |
We're seeing this one on Wikipedia as well, after we updated from an older Ace in mid-January. When editing articles we embed Ace as a "code" editor and for math formulas, both of which involve popping up a dialog containing the editor. We think it's that Ace's new size calculations fail if they run while that dialog opening animation is running, whereas the older method worked fine. |
@kemayo thanks, the example you provided have helped to track down the issue. It is happening because getBoundingClientRect returns height in transformed coordinates and clientHeight in local coordinates. This same change have broken https://raw.githack.com/ajaxorg/ace-builds/master/demo/transform.html as well. |
Describe the bug
I assume the change in #4996 results in a different calculation of line heights. Since 1.13.1 (I confirmed 1.13.0 does not have this issue) the line heights are incorrect and result in the text being smashed together. Manually requesting a browser zoom in or out will re-render the lines correctly.
Expected Behavior
Previously in 1.13.0 this rendered correctly.
Current Behavior
Here's an example of the initial display:
Reproduction Steps
I'm mounting this within a Vue.js component but it's pretty straightforward except perhaps it's running on the mounted life cycle method. Not sure if that's resulting in a browser environment that can't figure out the proper line height?
Possible Solution
No response
Additional Information/Context
Vue mounted lifecycle hook says:
A component is considered mounted after:
All of its synchronous child components have been mounted (does not include async components or components inside trees).
Its own DOM tree has been created and inserted into the parent container. Note it only guarantees that the component's DOM tree is in-document if the application's root container is also in-document.
This hook is typically used for performing side effects that need access to the component's rendered DOM
Ace Version / Browser / OS / Keyboard layout
1.13.1 / Chrome (107.0.5304.87) / Mac OS 13 / Querty
The text was updated successfully, but these errors were encountered: