Skip to content
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

[Console] Fix floating tools rendering logic #54505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function EditorUI() {

mappings.retrieveAutoCompleteInfo();

const unsubscribeResizer = subscribeResizeChecker(editorRef.current!, editor.getCoreEditor());
const unsubscribeResizer = subscribeResizeChecker(editorRef.current!, editor);
setupAutosave();

return () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ export function subscribeResizeChecker(el: HTMLElement, ...editors: any[]) {
const checker = new ResizeChecker(el);
checker.on('resize', () =>
editors.forEach(e => {
e.resize();
if (e.updateActionsBar) e.updateActionsBar();
if (e.getCoreEditor) {
e.getCoreEditor().resize();
} else {
e.resize();
}

if (e.updateActionsBar) {
e.updateActionsBar();
}
})
);
return () => checker.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,30 +297,30 @@ export class LegacyCoreEditor implements CoreEditor {
// pageY is relative to page, so subtract the offset
// from pageY to get the new top value
const offsetFromPage = $(this.editor.container).offset()!.top;
const startRow = range.start.lineNumber - 1;
const startLine = range.start.lineNumber;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: at first glance, i don't think the const name startLine is clear in how it differs from firstLine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this #52270 was merged a distinction was created between row (zero indexed) and line (not-zero indexed). This was informed by the approach taken by Monaco 😅

const startColumn = range.start.column;
const firstLine = this.getLineValue(startRow);
const firstLine = this.getLineValue(startLine);
const maxLineLength = this.getWrapLimit() - 5;
const isWrapping = firstLine.length > maxLineLength;
const getScreenCoords = (row: number) =>
this.editor.renderer.textToScreenCoordinates(row, startColumn).pageY - offsetFromPage;
const topOfReq = getScreenCoords(startRow);
const getScreenCoords = (line: number) =>
this.editor.renderer.textToScreenCoordinates(line - 1, startColumn).pageY - offsetFromPage;
const topOfReq = getScreenCoords(startLine);

if (topOfReq >= 0) {
let offset = 0;
if (isWrapping) {
// Try get the line height of the text area in pixels.
const textArea = $(this.editor.container.querySelector('textArea')!);
const hasRoomOnNextLine = this.getLineValue(startRow + 1).length < maxLineLength;
const hasRoomOnNextLine = this.getLineValue(startLine).length < maxLineLength;
if (textArea && hasRoomOnNextLine) {
// Line height + the number of wraps we have on a line.
offset += this.getLineValue(startRow).length * textArea.height()!;
offset += this.getLineValue(startLine).length * textArea.height()!;
} else {
if (startRow > 0) {
this.setActionsBar(getScreenCoords(startRow - 1));
if (startLine > 1) {
this.setActionsBar(getScreenCoords(startLine - 1));
return;
}
this.setActionsBar(getScreenCoords(startRow + 1));
this.setActionsBar(getScreenCoords(startLine + 1));
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function(editor: any) {
const resize = editor.resize;

const throttledResize = throttle(() => {
resize.call(editor);
resize.call(editor, false);

// Keep current top line in view when resizing to avoid losing user context
const userRow = get(throttledResize, 'topRow', 0);
Expand Down