-
-
Notifications
You must be signed in to change notification settings - Fork 302
feat(texteditor): add text alignment toggling buttons #5677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4aebc0e
e54e72d
baac181
d6b9621
c270ce4
f2aa6e6
74341c4
22a5c2d
38a9805
c3d1cbe
2dd5003
f17bbf6
f3bc749
dbc30f2
c7cf5ee
42d8179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -404,6 +404,7 @@ | |
| } | ||
|
|
||
| .editor-container small { | ||
| display: block; | ||
| margin: 4px 0; | ||
| font-size: 12px; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,23 @@ import { sanitizePastedHTML } from '../utils/markdown'; | |
| export function useToolbarActions(emit) { | ||
| const editor = inject('editor', null); | ||
|
|
||
| // helper | ||
| const getEffectiveAlignment = editorInstance => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: |
||
| if (!editorInstance) return 'left'; | ||
|
|
||
| const isLeftAligned = editorInstance.isActive({ textAlign: 'left' }); | ||
| const isRightAligned = editorInstance.isActive({ textAlign: 'right' }); | ||
|
|
||
| if (isLeftAligned) return 'left'; | ||
| if (isRightAligned) return 'right'; | ||
|
|
||
| const { from } = editorInstance.state.selection; | ||
| const dom = editorInstance.view.domAtPos(from).node; | ||
| const el = dom.nodeType === 1 ? dom : dom.parentElement; | ||
|
|
||
| return el ? window.getComputedStyle(el).textAlign : 'left'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: Smart fallback to |
||
| }; | ||
|
|
||
| const { | ||
| undo$, | ||
| redo$, | ||
|
|
@@ -21,6 +38,8 @@ export function useToolbarActions(emit) { | |
| mathFormula$, | ||
| codeBlock$, | ||
| clipboardAccessFailed$, | ||
| alignLeft$, | ||
| alignRight$, | ||
| } = getTipTapEditorStrings(); | ||
|
|
||
| // Action handlers | ||
|
|
@@ -181,6 +200,18 @@ export function useToolbarActions(emit) { | |
| } | ||
| }; | ||
|
|
||
| const handleToggleAlign = () => { | ||
| if (!editor?.value) return; | ||
|
|
||
| const align = getEffectiveAlignment(editor.value); | ||
|
|
||
| editor.value | ||
| .chain() | ||
| .focus() | ||
| .setTextAlign(align === 'right' ? 'left' : 'right') | ||
| .run(); | ||
| }; | ||
|
|
||
| const handleBulletList = () => { | ||
| if (editor?.value) { | ||
| editor.value.chain().focus().toggleBulletList().run(); | ||
|
|
@@ -418,6 +449,23 @@ export function useToolbarActions(emit) { | |
| handler: handleMinimize, | ||
| }; | ||
|
|
||
| const alignAction = computed(() => { | ||
| const editorInstance = editor?.value; | ||
| const effectiveAlign = getEffectiveAlignment(editorInstance); | ||
|
habibayman marked this conversation as resolved.
|
||
| const effectiveRight = effectiveAlign === 'right'; | ||
|
|
||
| return { | ||
| name: 'toggleAlign', | ||
| title: effectiveRight ? alignLeft$() : alignRight$(), | ||
| icon: effectiveRight | ||
| ? require('../../assets/icon-alignLeft.svg') | ||
| : require('../../assets/icon-alignRight.svg'), | ||
| handler: handleToggleAlign, | ||
| isActive: false, | ||
| isAvailable: !isMarkActive('codeBlock'), | ||
| }; | ||
| }); | ||
|
|
||
| return { | ||
| // Individual handlers | ||
| handleUndo, | ||
|
|
@@ -429,6 +477,7 @@ export function useToolbarActions(emit) { | |
| handleCopy, | ||
| handlePaste, | ||
| handlePasteNoFormat, | ||
| handleToggleAlign, | ||
| handleBulletList, | ||
| handleNumberList, | ||
| handleSubscript, | ||
|
|
@@ -444,6 +493,7 @@ export function useToolbarActions(emit) { | |
| // Action arrays | ||
| historyActions, | ||
| textActions, | ||
| alignAction, | ||
| listActions, | ||
| scriptActions, | ||
| insertTools, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: The align button here doesn't bind
:is-available="alignAction.isAvailable", unlike the desktopEditorToolbar.vue(line 77). This means the align button won't be disabled inside code blocks on mobile. Consider adding:is-available="alignAction.isAvailable"for parity.