mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
code box UI
This commit is contained in:
parent
a435a59a2e
commit
6630d596f6
3 changed files with 35 additions and 20 deletions
|
|
@ -4,8 +4,6 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import React, { ReactNode } from "react"
|
||||
import SyntaxHighlighter from "react-syntax-highlighter";
|
||||
import { atomOneDarkReasonable } from "react-syntax-highlighter/dist/esm/styles/hljs";
|
||||
import { VoidCodeEditor } from '../util/inputs.js';
|
||||
|
||||
|
||||
|
|
@ -71,19 +69,11 @@ export function getLanguageFromFileName(fileName: string): string {
|
|||
|
||||
export const BlockCode = ({ text, buttonsOnHover, language }: { text: string, buttonsOnHover?: ReactNode, language?: string }) => {
|
||||
|
||||
const customStyle = {
|
||||
...atomOneDarkReasonable,
|
||||
'code[class*="language-"]': {
|
||||
...atomOneDarkReasonable['code[class*="language-"]'],
|
||||
background: "none",
|
||||
},
|
||||
}
|
||||
|
||||
return (<>
|
||||
<div className={`relative group w-full bg-vscode-sidebar-bg overflow-hidden isolate`}>
|
||||
|
||||
{buttonsOnHover === null ? null : (
|
||||
<div className="absolute top-0 right-0 opacity-0 group-hover:opacity-100 duration-200">
|
||||
<div className="z-[1] absolute top-0 right-0 opacity-0 group-hover:opacity-100 duration-200">
|
||||
<div className="flex space-x-2 p-2">{buttonsOnHover}</div>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -299,6 +299,7 @@ export const VoidCodeEditor = ({ initValue, language }: { initValue: string, lan
|
|||
|
||||
return <div ref={divRef}>
|
||||
<WidgetComponent
|
||||
className='relative z-0'
|
||||
ctor={useCallback((container) =>
|
||||
instantiationService.createInstance(
|
||||
CodeEditorWidget,
|
||||
|
|
@ -306,22 +307,34 @@ export const VoidCodeEditor = ({ initValue, language }: { initValue: string, lan
|
|||
{
|
||||
automaticLayout: true,
|
||||
wordWrap: 'off',
|
||||
|
||||
scrollbar: {
|
||||
alwaysConsumeMouseWheel: false,
|
||||
vertical: 'auto',
|
||||
horizontal: 'auto',
|
||||
alwaysConsumeMouseWheel: false
|
||||
},
|
||||
scrollBeyondLastLine: false,
|
||||
|
||||
lineNumbers: 'off',
|
||||
|
||||
readOnly: true,
|
||||
domReadOnly: true,
|
||||
readOnlyMessage: { value: '' },
|
||||
|
||||
minimap: {
|
||||
enabled: false,
|
||||
// maxColumn: 0,
|
||||
},
|
||||
|
||||
selectionHighlight: false, // highlights whole words
|
||||
renderLineHighlight: 'none',
|
||||
|
||||
folding: false,
|
||||
lineDecorationsWidth: 0,
|
||||
scrollBeyondLastLine: false,
|
||||
minimap: { enabled: false },
|
||||
overviewRulerLanes: 0,
|
||||
hideCursorInOverviewRuler: true,
|
||||
overviewRulerBorder: false,
|
||||
renderLineHighlight: 'none',
|
||||
glyphMargin: false,
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
isSimpleWidget: true,
|
||||
|
|
|
|||
|
|
@ -35,10 +35,11 @@ class VoidSettingsInput extends EditorInput {
|
|||
|
||||
static readonly ID: string = 'workbench.input.void.settings';
|
||||
|
||||
readonly resource = URI.from({
|
||||
scheme: 'void-editor-settings',
|
||||
path: 'void-settings' // Give it a unique path
|
||||
});
|
||||
static readonly RESOURCE = URI.from({ // I think this scheme is invalid, it just shuts up TS
|
||||
scheme: 'void', // Custom scheme for our editor
|
||||
path: 'settings'
|
||||
})
|
||||
readonly resource = VoidSettingsInput.RESOURCE;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
|
@ -140,9 +141,20 @@ registerAction2(class extends Action2 {
|
|||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(accessor: ServicesAccessor): Promise<void> {
|
||||
const editorService = accessor.get(IEditorService);
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
|
||||
const openEditors = editorService.findEditors(VoidSettingsInput.RESOURCE);
|
||||
|
||||
// close all instances if found
|
||||
if (openEditors.length > 0) {
|
||||
await editorService.closeEditors(openEditors);
|
||||
return;
|
||||
}
|
||||
|
||||
// else open it
|
||||
const input = instantiationService.createInstance(VoidSettingsInput);
|
||||
await editorService.openEditor(input);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue