mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-08-29 10:09:26 +02:00
Compare commits
5 Commits
3.4.5-andr
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29a461dffb | ||
|
|
95fa1efe2b | ||
|
|
0e6f123265 | ||
|
|
01dcf8c17a | ||
|
|
a711873e1c |
@@ -106,6 +106,8 @@ export const BlockId = Extension.create({
|
||||
if (updates.length > 0) {
|
||||
tr.step(new BatchAttributeStep(updates));
|
||||
tr.setMeta("ignoreEdit", true);
|
||||
// Transaction.addStep always clears storedMarks
|
||||
if (newState.storedMarks) tr.setStoredMarks(newState.storedMarks);
|
||||
return tr;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ export const FontFamily = Extension.create<FontFamilyOptions>({
|
||||
attributes: {
|
||||
fontFamily: {
|
||||
default: null,
|
||||
keepOnSplit: true,
|
||||
parseHTML: (element) =>
|
||||
element.style.fontFamily?.replace(/['"]+/g, ""),
|
||||
renderHTML: (attributes) => {
|
||||
|
||||
@@ -95,7 +95,8 @@ export const Paragraph = Node.create<ParagraphOptions>({
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
Enter: ({ editor }) => {
|
||||
if (this.options.doubleSpaced) return false;
|
||||
if (this.options.doubleSpaced)
|
||||
return editor.commands.splitBlock({ keepMarks: true });
|
||||
|
||||
const { state } = editor;
|
||||
const { selection } = state;
|
||||
@@ -105,17 +106,16 @@ export const Paragraph = Node.create<ParagraphOptions>({
|
||||
if (
|
||||
!empty ||
|
||||
$from.parent.type !== this.type ||
|
||||
$from.depth > 1 ||
|
||||
atEnd
|
||||
$from.depth > 1
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!atEnd) {
|
||||
return createParagraph(editor, this.type, false, true);
|
||||
if (atEnd) {
|
||||
return editor.commands.splitBlock({ keepMarks: true });
|
||||
}
|
||||
|
||||
return false;
|
||||
return createParagraph(editor, this.type, false, true);
|
||||
},
|
||||
"Mod-Enter": ({ editor }) =>
|
||||
createParagraph(editor, this.type, false, true),
|
||||
|
||||
@@ -25,7 +25,7 @@ import { useCallback, useMemo } from "react";
|
||||
import { Counter } from "../components/counter.js";
|
||||
import { useRefValue } from "../../hooks/use-ref-value.js";
|
||||
import { useToolbarStore } from "../stores/toolbar-store.js";
|
||||
import { getFontById, getFontIds, getFonts } from "../../utils/font.js";
|
||||
import { getFont, getFontById, getFonts } from "../../utils/font.js";
|
||||
import { CodeBlock } from "../../extensions/code-block/index.js";
|
||||
import { strings } from "@notesnook/intl";
|
||||
|
||||
@@ -66,10 +66,10 @@ export function FontSize(props: ToolProps) {
|
||||
export function FontFamily(props: ToolProps) {
|
||||
const { editor } = props;
|
||||
const defaultFontFamily = useToolbarStore((store) => store.fontFamily);
|
||||
const currentFontFamily =
|
||||
getFontIds().find((id) =>
|
||||
editor.isActive("textStyle", { fontFamily: id })
|
||||
) || defaultFontFamily;
|
||||
const currentFontFamily = editor.getAttributes("textStyle").fontFamily;
|
||||
const selectedFont = currentFontFamily
|
||||
? getFont(currentFontFamily)
|
||||
: getFontById(defaultFontFamily);
|
||||
|
||||
const items = useMemo(
|
||||
() => toMenuItems(editor, currentFontFamily),
|
||||
@@ -81,7 +81,7 @@ export function FontFamily(props: ToolProps) {
|
||||
<Dropdown
|
||||
id="fontFamily"
|
||||
group="font"
|
||||
selectedItem={getFontById(currentFontFamily)?.title || defaultFontFamily}
|
||||
selectedItem={selectedFont?.title || defaultFontFamily}
|
||||
items={items}
|
||||
menuWidth={130}
|
||||
disabled={editor.isActive(CodeBlock.name)}
|
||||
|
||||
@@ -45,6 +45,20 @@ export function getFontById(id: string) {
|
||||
return FONTS.find((a) => a.id === id);
|
||||
}
|
||||
|
||||
export function getFont(font: string) {
|
||||
return FONTS.find(
|
||||
(a) => normalizeFontFamily(a.font) === normalizeFontFamily(font)
|
||||
);
|
||||
}
|
||||
|
||||
export function getFontIds() {
|
||||
return FONTS.map((a) => a.id);
|
||||
}
|
||||
|
||||
function normalizeFontFamily(fontFamily: string) {
|
||||
return fontFamily
|
||||
.replace(/['"]+/g, "")
|
||||
.replaceAll(", ", ",")
|
||||
.replaceAll(",", "")
|
||||
.replace(/\s+/g, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user