Skip to content

Commit

Permalink
bug: Unbullet one list item not the whole list
Browse files Browse the repository at this point in the history
  • Loading branch information
umaranis committed May 6, 2024
1 parent 22ce853 commit 0815f5a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script lang="ts">
import {
INSERT_UNORDERED_LIST_COMMAND,
REMOVE_LIST_COMMAND,
} from '@lexical/list';
import {INSERT_UNORDERED_LIST_COMMAND} from '@lexical/list';
import {getContext} from 'svelte';
import type {Writable} from 'svelte/store';
import {getEditor} from '$lib/core/composerContext.js';
import DropDownItem from '../../generic/dropdown/DropDownItem.svelte';
import type {blockTypeToBlockName} from './blockTypeToBlockName.js';
import {formatParagraph} from './formatParagraph.js';
const blockType: Writable<keyof typeof blockTypeToBlockName> =
getContext('blockType');
Expand All @@ -17,7 +15,7 @@
if ($blockType !== 'bullet') {
editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
} else {
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
formatParagraph(editor);
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts">
import {INSERT_CHECK_LIST_COMMAND, REMOVE_LIST_COMMAND} from '@lexical/list';
import {INSERT_CHECK_LIST_COMMAND} from '@lexical/list';
import {getContext} from 'svelte';
import type {Writable} from 'svelte/store';
import {getEditor} from '$lib/core/composerContext.js';
import DropDownItem from '../../generic/dropdown/DropDownItem.svelte';
import type {blockTypeToBlockName} from './blockTypeToBlockName.js';
import {formatParagraph} from './formatParagraph.js';
const blockType: Writable<keyof typeof blockTypeToBlockName> =
getContext('blockType');
Expand All @@ -14,7 +15,7 @@
if ($blockType !== 'check') {
editor.dispatchCommand(INSERT_CHECK_LIST_COMMAND, undefined);
} else {
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
formatParagraph(editor);
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script lang="ts">
import {
INSERT_ORDERED_LIST_COMMAND,
REMOVE_LIST_COMMAND,
} from '@lexical/list';
import {INSERT_ORDERED_LIST_COMMAND} from '@lexical/list';
import {getContext} from 'svelte';
import type {Writable} from 'svelte/store';
import {getEditor} from '$lib/core/composerContext.js';
import DropDownItem from '../../generic/dropdown/DropDownItem.svelte';
import type {blockTypeToBlockName} from './blockTypeToBlockName.js';
import {formatParagraph} from './formatParagraph.js';
const blockType: Writable<keyof typeof blockTypeToBlockName> =
getContext('blockType');
Expand All @@ -17,7 +15,7 @@
if ($blockType !== 'number') {
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
} else {
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
formatParagraph(editor);
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {$setBlocksType} from '@lexical/selection';
import {$createParagraphNode, $getSelection, type LexicalEditor} from 'lexical';

export function formatParagraph(editor: LexicalEditor) {
editor.update(() => {
const selection = $getSelection();
$setBlocksType(selection, () => $createParagraphNode());
});
}

0 comments on commit 0815f5a

Please sign in to comment.