Skip to content

Commit

Permalink
add workaround to squashed command palette in small cypher editors (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrEmil authored Mar 5, 2021
1 parent c6b362f commit 69f0f21
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/browser/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,13 @@ declare module 'cypher-editor-support' {
}
}
}

declare module 'monaco-editor/esm/vs/base/parts/quickinput/browser/quickInputList' {
export class QuickInputList {
layout: (maxHeight: number) => void
list: {
getHTMLElement: () => HTMLElement
layout: () => void
}
}
}
19 changes: 19 additions & 0 deletions src/browser/modules/Editor/Monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { QuickInputList } from 'monaco-editor/esm/vs/base/parts/quickinput/browser/quickInputList'
import { parse } from 'cypher-editor-support'
import { debounce } from 'lodash-es'
import {
Expand Down Expand Up @@ -223,6 +224,24 @@ const Monaco = forwardRef<MonacoHandles, MonacoProps>(
})
resizeObserver.observe(container)

/*
* This moves the the command palette widget out of of the overflow-guard div where overlay widgets
* are located, into the overflowing content widgets div.
* This solves the command palette being squashed when the cypher editor is only a few lines high.
* The workaround is based on a suggestion found in the github issue: https://github.com/microsoft/monaco-editor/issues/70
*/
const quickInputDOMNode = editorRef.current.getContribution<
{ widget: { domNode: HTMLElement } } & editor.IEditorContribution
>('editor.controller.quickInput').widget.domNode
;(editorRef.current as any)._modelData.view._contentWidgets.overflowingContentWidgetsDomNode.domNode.appendChild(
quickInputDOMNode.parentNode?.removeChild(quickInputDOMNode)
)
QuickInputList.prototype.layout = function(maxHeight: number) {
this.list.getHTMLElement().style.maxHeight =
maxHeight < 200 ? '200px' : Math.floor(maxHeight) + 'px'
this.list.layout()
}

return () => {
editorRef.current?.dispose()
debouncedUpdateCode.cancel()
Expand Down

0 comments on commit 69f0f21

Please sign in to comment.