Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const tokens = line.substring(0, end).split(/\W+/);
const last = tokens[tokens.length - 1];
const start = last ? end - last.length : end;
const position = editor.getPositionAt(start);
if (!position) {
return;
}
const anchor = editor.getCoordinateForPosition(position) as ClientRect;
const style = window.getComputedStyle(this.node);
const paddingLeft = parseInt(style.paddingLeft!, 10) || 0;
// Calculate the geometry of the tooltip.
HoverBox.setGeometry({
anchor,
host: editor.host,
maxHeight: MAX_HEIGHT,
minHeight: MIN_HEIGHT,
node: this.node,
offset: { horizontal: -1 * paddingLeft },
privilege: 'below',
style: style
});
}
const tokens = line.substring(0, end).split(/\W+/);
const last = tokens[tokens.length - 1];
const start = last ? end - last.length : end;
const position = editor.getPositionAt(start);
if (!position) {
return;
}
const anchor = editor.getCoordinateForPosition(position) as ClientRect;
const style = window.getComputedStyle(this.node);
const paddingLeft = parseInt(style.paddingLeft!, 10) || 0;
// Calculate the geometry of the tooltip.
HoverBox.setGeometry({
anchor,
host: editor.host,
maxHeight: MAX_HEIGHT,
minHeight: MIN_HEIGHT,
node: this.node,
offset: { horizontal: -1 * paddingLeft },
privilege: 'below',
style: style
});
}
private _setGeometry(): void {
// Find the start of the current token for hover box placement.
const editor = this._editor;
const cursor = editor.getCursorPosition();
const end = editor.getOffsetAt(cursor);
const line = editor.getLine(cursor.line);
const tokens = line.substring(0, end).split(/\W+/);
const last = tokens[tokens.length - 1];
const start = last ? end - last.length : end;
const position = editor.getPositionAt(start);
const anchor = editor.getCoordinateForPosition(position) as ClientRect;
const style = window.getComputedStyle(this.node);
const paddingLeft = parseInt(style.paddingLeft, 10) || 0;
// Calculate the geometry of the tooltip.
HoverBox.setGeometry({
anchor,
host: editor.host,
maxHeight: MAX_HEIGHT,
minHeight: MIN_HEIGHT,
node: this.node,
offset: { horizontal: -1 * paddingLeft },
privilege: 'below'
});
}
// This is an overly defensive test: `cursor` will always exist if
// `original` exists, except in contrived tests. But since it is possible
// to generate a runtime error, the check occurs here.
if (!editor || !model || !model.original || !model.cursor) {
return;
}
const start = model.cursor.start;
const position = editor.getPositionAt(start) as CodeEditor.IPosition;
const anchor = editor.getCoordinateForPosition(position) as ClientRect;
const style = window.getComputedStyle(node);
const borderLeft = parseInt(style.borderLeftWidth!, 10) || 0;
const paddingLeft = parseInt(style.paddingLeft!, 10) || 0;
// Calculate the geometry of the completer.
HoverBox.setGeometry({
anchor,
host: editor.host,
maxHeight: MAX_HEIGHT,
minHeight: MIN_HEIGHT,
node: node,
offset: { horizontal: borderLeft + paddingLeft },
privilege: 'below',
style: style
});
}
private _setGeometry(): void {
let aligned = 0;
const anchorRect = this._anchor.node.getBoundingClientRect();
const bodyRect = this._body.node.getBoundingClientRect();
if (this._align === 'right') {
aligned = -(bodyRect.width - anchorRect.width);
}
const style = window.getComputedStyle(this._body.node);
HoverBox.setGeometry({
anchor: anchorRect,
host: document.body,
maxHeight: 500,
minHeight: 20,
node: this._body.node,
offset: {
horizontal: aligned
},
privilege: 'forceAbove',
style
});
}