+
+
+function setInsetForSelection(editor: LexicalEditor, change: number): void {
+ const selection = getLastSelection(editor);
+
+ const elements = $getBlockElementNodesInSelection(selection);
+ for (const node of elements) {
+ if (nodeHasInset(node)) {
+ const currentInset = node.getInset();
+ const newInset = Math.min(Math.max(currentInset + change, 0), 500);
+ node.setInset(newInset)
+ }
+ }
+
+ $toggleSelection(editor);
+}
+
+export const indentIncrease: EditorButtonDefinition = {
+ label: 'Increase indent',
+ icon: indentIncreaseIcon,
+ action(context: EditorUiContext) {
+ context.editor.update(() => {
+ setInsetForSelection(context.editor, 40);
+ });
+ },
+ isActive() {
+ return false;
+ }
+};
+
+export const indentDecrease: EditorButtonDefinition = {
+ label: 'Decrease indent',
+ icon: indentDecreaseIcon,
+ action(context: EditorUiContext) {
+ context.editor.update(() => {
+ setInsetForSelection(context.editor, -40);
+ });
+ },
+ isActive() {
+ return false;
+ }
+};
\ No newline at end of file