Skip to content
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

Add textarea widget spell check setting #627

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ watchEffect(() => {
)
})

watchEffect(() => {
const spellcheckEnabled = settingStore.get('Comfy.TextareaWidget.Spellcheck')
const textareas = document.querySelectorAll('textarea.comfy-multiline-input')

textareas.forEach((textarea: HTMLTextAreaElement) => {
textarea.spellcheck = spellcheckEnabled
// Force recheck to ensure visual update
textarea.focus()
textarea.blur()
})
})

let dropTargetCleanup = () => {}

onMounted(async () => {
Expand Down
9 changes: 7 additions & 2 deletions src/scripts/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './domWidget'
import type { ComfyApp } from './app'
import type { IWidget, LGraphNode } from '@comfyorg/litegraph'
import { ComfyNodeDef } from '@/types/apiTypes'
import { useSettingStore } from '@/stores/settingStore'

export type ComfyWidgetConstructor = (
node: LGraphNode,
Expand Down Expand Up @@ -312,12 +313,16 @@ function createIntWidget(
}
}

function addMultilineWidget(node, name, opts, app) {
function addMultilineWidget(node, name: string, opts, app: ComfyApp) {
const inputEl = document.createElement('textarea')
inputEl.className = 'comfy-multiline-input'
inputEl.value = opts.defaultVal
inputEl.placeholder = opts.placeholder || name
inputEl.spellcheck = opts.spellcheck || false
if (app.vueAppReady) {
inputEl.spellcheck = useSettingStore().get(
'Comfy.TextareaWidget.Spellcheck'
)
}

const widget = node.addDOMWidget(name, 'customtext', inputEl, {
getValue() {
Expand Down
8 changes: 8 additions & 0 deletions src/stores/settingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ export const useSettingStore = defineStore('setting', {
}
})

app.ui.settings.addSetting({
id: 'Comfy.TextareaWidget.Spellcheck',
category: ['Comfy', 'Node Widget', 'TextareaWidget', 'Spellcheck'],
name: 'Textarea widget spellcheck',
type: 'boolean',
defaultValue: false
})

app.ui.settings.addSetting({
id: 'Comfy.Workflow.SortNodeIdOnSave',
name: 'Sort node IDs when saving workflow',
Expand Down
4 changes: 2 additions & 2 deletions src/types/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ const zStringInputSpec = inputSpec([

// Multiline-only fields
defaultVal: z.string().optional(),
placeholder: z.string().optional(),
spellcheck: z.boolean().optional()
placeholder: z.string().optional()
})
])

Expand Down Expand Up @@ -448,6 +447,7 @@ const zSettings = z.record(z.any()).and(
'Comfy.SwitchUser': z.any(),
'Comfy.SnapToGrid.GridSize': z.number(),
'Comfy.TextareaWidget.FontSize': z.number(),
'Comfy.TextareaWidget.Spellcheck': z.boolean(),
'Comfy.UseNewMenu': z.any(),
'Comfy.Validation.Workflows': z.boolean(),
'Comfy.Workflow.SortNodeIdOnSave': z.boolean()
Expand Down
Loading