Skip to content

Commit

Permalink
Fix floating tools rendering logic (elastic#54505)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
jloleysens and elasticmachine committed Jan 13, 2020
1 parent a64013f commit c39d8e2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
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;
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

0 comments on commit c39d8e2

Please sign in to comment.