Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix codeblock info bar style

ammarahm-ed8ad5006b4768
diff --git a/packages/editor/dist/es/extensions/codeblock/component.js b/packages/editor/dist/es/extensions/codeblock/component.js
index e4efe44af..11264b527 100644
--- a/packages/editor/dist/es/extensions/codeblock/component.js
+++ b/packages/editor/dist/es/extensions/codeblock/component.js
@@ -37,7 +37,7 @@ export function CodeblockComponent(props) {
refractor.register(syntax);
const preventUpdate = language === languageDefinition.filename;
updateAttributes({
- language: languageDefinition.filename,
+ language: languageDefinition.filename
}, { preventUpdate, addToHistory: false });
});
})();
@@ -45,13 +45,13 @@ export function CodeblockComponent(props) {
return (_jsxs(_Fragment, { children: [_jsxs(Flex, Object.assign({ sx: {
flexDirection: "column",
borderRadius: "default",
- overflow: "hidden",
- } }, { children: [_jsx(Text, { ref: forwardRef, as: "pre", sx: {
+ overflow: "hidden"
+ } }, { children: [_jsx(Text, { ref: forwardRef, as: "pre", autoCorrect: "off", autoCapitalize: "none", sx: {
"div, span.token, span.line-number-widget, span.line-number::before": {
fontFamily: "monospace",
fontSize: "code",
whiteSpace: "pre !important",
- tabSize: 1,
+ tabSize: 1
},
position: "relative",
lineHeight: "20px",
@@ -61,24 +61,24 @@ export function CodeblockComponent(props) {
display: "flex",
px: 2,
pt: 2,
- pb: 1,
+ pb: 1
}, spellCheck: false }), _jsxs(Flex, Object.assign({ ref: toolbarRef, contentEditable: false, sx: {
bg: "codeBg",
alignItems: "center",
- justifyContent: "end",
- borderTop: "1px solid var(--codeBorder)",
+ justifyContent: "flex-end",
+ borderTop: "1px solid var(--codeBorder)"
} }, { children: [caretPosition ? (_jsxs(Text, Object.assign({ variant: "subBody", sx: { mr: 2, color: "codeFg" } }, { children: ["Line ", caretPosition.line, ", Column ", caretPosition.column, " ", caretPosition.selected
? `(${caretPosition.selected} selected)`
: ""] }))) : null, _jsx(Button, Object.assign({ variant: "icon", sx: { p: 1, mr: 1, ":hover": { bg: "codeSelection" } }, title: "Toggle indentation mode", onClick: () => {
editor.commands.changeCodeBlockIndentation({
type: indentType === "space" ? "tab" : "space",
- amount: indentLength,
+ amount: indentLength
});
} }, { children: _jsxs(Text, Object.assign({ variant: "subBody", sx: { color: "codeFg" } }, { children: [indentType === "space" ? "Spaces" : "Tabs", ": ", indentLength] })) })), _jsx(Button, Object.assign({ variant: "icon", sx: {
p: 1,
mr: 1,
bg: isOpen ? "codeSelection" : "transparent",
- ":hover": { bg: "codeSelection" },
+ ":hover": { bg: "codeSelection" }
}, onClick: () => {
setIsOpen(true);
}, title: "Change language" }, { children: _jsx(Text, Object.assign({ variant: "subBody", spellCheck: false, sx: { color: "codeFg" } }, { children: (languageDefinition === null || languageDefinition === void 0 ? void 0 : languageDefinition.title) || "Plaintext" })) }))] }))] })), _jsx(ResponsivePresenter, Object.assign({ isOpen: isOpen, onClose: () => {
@@ -95,7 +95,7 @@ export function CodeblockComponent(props) {
align: "end",
isTargetAbsolute: true,
location: "top",
- yOffset: 5,
+ yOffset: 5
}, title: "Change code block language" }, { children: _jsx(LanguageSelector, { selectedLanguage: (languageDefinition === null || languageDefinition === void 0 ? void 0 : languageDefinition.filename) || "Plaintext", onLanguageSelected: (language) => {
updateAttributes({ language }, { addToHistory: true, preventUpdate: false });
setIsOpen(false);
@@ -109,7 +109,7 @@ function LanguageSelector(props) {
height: 200,
width: ["auto", 300],
overflowY: "auto",
- bg: "background",
+ bg: "background"
} }, { children: [_jsx(Input, { onFocus: () => {
console.log("EHLLO!");
}, autoFocus: true, placeholder: "Search languages", sx: {
@@ -119,7 +119,7 @@ function LanguageSelector(props) {
bg: "background",
mx: 2,
p: "7px",
- zIndex: 999,
+ zIndex: 999
}, onChange: (e) => {
if (!e.target.value)
return setLanguages(Languages);
@@ -132,12 +132,12 @@ function LanguageSelector(props) {
} }), _jsx(Flex, Object.assign({ sx: {
flexDirection: "column",
pt: 1,
- mt: 1,
+ mt: 1
} }, { children: languages.map((lang) => (_jsxs(Button, Object.assign({ variant: "menuitem", sx: {
textAlign: "left",
py: 1,
display: "flex",
justifyContent: "space-between",
- alignItems: "center",
+ alignItems: "center"
}, onClick: () => onLanguageSelected(lang.filename) }, { children: [_jsx(Text, Object.assign({ variant: "body" }, { children: lang.title })), selectedLanguage === lang.filename ? (_jsx(Icon, { path: Icons.check, size: "small" })) : lang.alias ? (_jsx(Text, Object.assign({ variant: "subBody", sx: { fontSize: "10px" } }, { children: lang.alias.slice(0, 3).join(", ") }))) : null] }), lang.title))) }))] })) })));
}
diff --git a/packages/editor/dist/es/extensions/codeblock/highlighter.d.ts b/packages/editor/dist/es/extensions/codeblock/highlighter.d.ts
index e42464534..8a9b4718e 100644
--- a/packages/editor/dist/es/extensions/codeblock/highlighter.d.ts
+++ b/packages/editor/dist/es/extensions/codeblock/highlighter.d.ts
@@ -2,7 +2,7 @@ import { Plugin } from "prosemirror-state";
import { DecorationSet } from "prosemirror-view";
import { AddMarkStep, RemoveMarkStep, ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
export declare type MergedStep = AddMarkStep | RemoveMarkStep | ReplaceAroundStep | ReplaceStep;
-export declare function HighlighterPlugin({ name, defaultLanguage, }: {
+export declare function HighlighterPlugin({ name, defaultLanguage }: {
name: string;
defaultLanguage: string | null | undefined;
}): Plugin<DecorationSet>;
diff --git a/packages/editor/dist/es/extensions/codeblock/highlighter.js b/packages/editor/dist/es/extensions/codeblock/highlighter.js
index 59de5f0bb..57dd45cc1 100644
--- a/packages/editor/dist/es/extensions/codeblock/highlighter.js
+++ b/packages/editor/dist/es/extensions/codeblock/highlighter.js
@@ -2,7 +2,7 @@ import { Plugin, PluginKey } from "prosemirror-state";
import { Decoration, DecorationSet } from "prosemirror-view";
import { findChildren } from "@tiptap/core";
import { refractor } from "refractor/lib/core";
-import { toCaretPosition, toCodeLines, } from "./code-block";
+import { toCaretPosition, toCodeLines } from "./code-block";
function parseNodes(nodes, className = []) {
return nodes.reduce((result, node) => {
if (node.type === "comment" || node.type === "doctype")
@@ -32,16 +32,17 @@ function getLineDecoration(from, line, total, isActive) {
const attributes = {
class: `line-number ${isActive ? "active" : ""}`,
"data-line": String(line).padEnd(maxLength, " "),
+ autocapitalize: "none"
};
const spec = {
line: line,
active: isActive,
total,
- from,
+ from
};
return Decoration.inline(from, from + 1, attributes, spec);
}
-function getDecorations({ doc, name, defaultLanguage, caretPosition, }) {
+function getDecorations({ doc, name, defaultLanguage, caretPosition }) {
const decorations = [];
const languages = refractor.listLanguages();
findChildren(doc, (node) => node.type.name === name).forEach((block) => {
@@ -64,7 +65,7 @@ function getDecorations({ doc, name, defaultLanguage, caretPosition, }) {
const to = from + node.text.length;
if (node.classes.length) {
const decoration = Decoration.inline(from, to, {
- class: node.classes.join(" "),
+ class: node.classes.join(" ")
});
decorations.push(decoration);
}
@@ -73,7 +74,7 @@ function getDecorations({ doc, name, defaultLanguage, caretPosition, }) {
});
return DecorationSet.create(doc, decorations);
}
-export function HighlighterPlugin({ name, defaultLanguage, }) {
+export function HighlighterPlugin({ name, defaultLanguage }) {
const key = new PluginKey("highlighter");
return new Plugin({
key,
@@ -82,7 +83,7 @@ export function HighlighterPlugin({ name, defaultLanguage, }) {
return getDecorations({
doc: state.doc,
name,
- defaultLanguage,
+ defaultLanguage
});
},
apply: (transaction, decorationSet, oldState, newState) => {
@@ -117,17 +118,17 @@ export function HighlighterPlugin({ name, defaultLanguage, }) {
doc: transaction.doc,
name,
defaultLanguage,
- caretPosition: position,
+ caretPosition: position
});
}
decorationSet = getActiveLineDecorations(transaction.doc, decorationSet, position);
return decorationSet.map(transaction.mapping, transaction.doc);
- },
+ }
},
props: {
decorations(state) {
return key.getState(state);
- },
+ }
},
appendTransaction: (transactions, prevState, nextState) => {
const tr = nextState.tr;
@@ -154,7 +155,7 @@ export function HighlighterPlugin({ name, defaultLanguage, }) {
}
});
return modified ? tr : null;
- },
+ }
});
}
/**
@@ -178,7 +179,7 @@ function getActiveLineDecorations(doc, decorations, position) {
decorations = decorations.remove(lineDecorations);
const newDecorations = [];
for (const decoration of cloned) {
- const { from, spec: { line, total }, } = decoration;
+ const { from, spec: { line, total } } = decoration;
const isActive = line === (position === null || position === void 0 ? void 0 : position.line);
const newDecoration = getLineDecoration(from, line, (position === null || position === void 0 ? void 0 : position.total) || total, isActive);
newDecorations.push(newDecoration);
diff --git a/packages/editor/src/extensions/code-block/component.tsx b/packages/editor/src/extensions/code-block/component.tsx
index c54598f2a..425378dd6 100644
--- a/packages/editor/src/extensions/code-block/component.tsx
+++ b/packages/editor/src/extensions/code-block/component.tsx
@@ -39,7 +39,7 @@ export function CodeblockComponent(
const preventUpdate = language === languageDefinition.filename;
updateAttributes(
{
- language: languageDefinition.filename,
+ language: languageDefinition.filename
},
{ preventUpdate, addToHistory: false }
);
@@ -52,19 +52,21 @@ export function CodeblockComponent(
sx={{
flexDirection: "column",
borderRadius: "default",
- overflow: "hidden",
+ overflow: "hidden"
}}
>
<Text
ref={forwardRef}
as="pre"
+ autoCorrect="off"
+ autoCapitalize="none"
sx={{
"div, span.token, span.line-number-widget, span.line-number::before":
{
fontFamily: "monospace",
fontSize: "code",
whiteSpace: "pre !important",
- tabSize: 1,
+ tabSize: 1
},
position: "relative",
lineHeight: "20px",
@@ -74,7 +76,7 @@ export function CodeblockComponent(
display: "flex",
px: 2,
pt: 2,
- pb: 1,
+ pb: 1
}}
spellCheck={false}
/>
@@ -84,8 +86,8 @@ export function CodeblockComponent(
sx={{
bg: "codeBg",
alignItems: "center",
- justifyContent: "end",
- borderTop: "1px solid var(--codeBorder)",
+ justifyContent: "flex-end",
+ borderTop: "1px solid var(--codeBorder)"
}}
>
{caretPosition ? (
@@ -103,7 +105,7 @@ export function CodeblockComponent(
onClick={() => {
editor.commands.changeCodeBlockIndentation({
type: indentType === "space" ? "tab" : "space",
- amount: indentLength,
+ amount: indentLength
});
}}
>
@@ -117,7 +119,7 @@ export function CodeblockComponent(
p: 1,
mr: 1,
bg: isOpen ? "codeSelection" : "transparent",
- ":hover": { bg: "codeSelection" },
+ ":hover": { bg: "codeSelection" }
}}
onClick={() => {
setIsOpen(true);
@@ -154,7 +156,7 @@ export function CodeblockComponent(
align: "end",
isTargetAbsolute: true,
location: "top",
- yOffset: 5,
+ yOffset: 5
}}
title="Change code block language"
>
@@ -191,7 +193,7 @@ function LanguageSelector(props: LanguageSelectorProps) {
height: 200,
width: ["auto", 300],
overflowY: "auto",
- bg: "background",
+ bg: "background"
}}
>
<Input
@@ -207,7 +209,7 @@ function LanguageSelector(props: LanguageSelectorProps) {
bg: "background",
mx: 2,
p: "7px",
- zIndex: 999,
+ zIndex: 999
}}
onChange={(e) => {
if (!e.target.value) return setLanguages(Languages);
@@ -228,7 +230,7 @@ function LanguageSelector(props: LanguageSelectorProps) {
sx={{
flexDirection: "column",
pt: 1,
- mt: 1,
+ mt: 1
}}
>
{languages.map((lang) => (
@@ -240,7 +242,7 @@ function LanguageSelector(props: LanguageSelectorProps) {
py: 1,
display: "flex",
justifyContent: "space-between",
- alignItems: "center",
+ alignItems: "center"
}}
onClick={() => onLanguageSelected(lang.filename)}
>
diff --git a/packages/editor/src/extensions/code-block/highlighter.ts b/packages/editor/src/extensions/code-block/highlighter.ts
index 37c7cfccf..7148802fb 100644
--- a/packages/editor/src/extensions/code-block/highlighter.ts
+++ b/packages/editor/src/extensions/code-block/highlighter.ts
@@ -8,14 +8,14 @@ import {
AddMarkStep,
RemoveMarkStep,
ReplaceAroundStep,
- ReplaceStep,
+ ReplaceStep
} from "prosemirror-transform";
import {
CaretPosition,
CodeBlockAttributes,
getLines,
toCaretPosition,
- toCodeLines,
+ toCodeLines
} from "./code-block";
export type MergedStep =
@@ -64,12 +64,13 @@ function getLineDecoration(
const attributes = {
class: `line-number ${isActive ? "active" : ""}`,
"data-line": String(line).padEnd(maxLength, " "),
+ autocapitalize: "none"
};
const spec: any = {
line: line,
active: isActive,
total,
- from,
+ from
};
return Decoration.inline(from, from + 1, attributes, spec);
@@ -79,7 +80,7 @@ function getDecorations({
doc,
name,
defaultLanguage,
- caretPosition,
+ caretPosition
}: {
caretPosition?: CaretPosition;
doc: ProsemirrorNode;
@@ -115,7 +116,7 @@ function getDecorations({
const to = from + node.text.length;
if (node.classes.length) {
const decoration = Decoration.inline(from, to, {
- class: node.classes.join(" "),
+ class: node.classes.join(" ")
});
decorations.push(decoration);
}
@@ -128,7 +129,7 @@ function getDecorations({
export function HighlighterPlugin({
name,
- defaultLanguage,
+ defaultLanguage
}: {
name: string;
defaultLanguage: string | null | undefined;
@@ -142,7 +143,7 @@ export function HighlighterPlugin({
return getDecorations({
doc: state.doc,
name,
- defaultLanguage,
+ defaultLanguage
});
},
apply: (
@@ -196,7 +197,7 @@ export function HighlighterPlugin({
doc: transaction.doc,
name,
defaultLanguage,
- caretPosition: position,
+ caretPosition: position
});
}
@@ -207,13 +208,13 @@ export function HighlighterPlugin({
);
return decorationSet.map(transaction.mapping, transaction.doc);
- },
+ }
},
props: {
decorations(state) {
return key.getState(state);
- },
+ }
},
appendTransaction: (transactions, prevState, nextState) => {
@@ -254,7 +255,7 @@ export function HighlighterPlugin({
);
return modified ? tr : null;
- },
+ }
});
}
@@ -292,7 +293,7 @@ function getActiveLineDecorations(
for (const decoration of cloned) {
const {
from,
- spec: { line, total },
+ spec: { line, total }
} = decoration;
const isActive = line === position?.line;