Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
56 changes: 28 additions & 28 deletions docs/src/content/docs/features/keyboard/shortcuts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ keyBindings := app.KeyBinding
Register a simple keyboard shortcut:

```go
app.KeyBinding.Add("Ctrl+S", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+S", func(window application.Window) {
// Handle save action
app.Logger.Info("Save shortcut triggered")
// Perform save operation...
Expand All @@ -42,36 +42,36 @@ Register multiple shortcuts for common operations:

```go
// File operations
app.KeyBinding.Add("Ctrl+N", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+N", func(window application.Window) {
// New file
window.EmitEvent("file:new", nil)
})

app.KeyBinding.Add("Ctrl+O", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+O", func(window application.Window) {
// Open file
dialog := app.Dialog.OpenFile()
if file, err := dialog.PromptForSingleSelection(); err == nil {
window.EmitEvent("file:open", file)
}
})

app.KeyBinding.Add("Ctrl+S", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+S", func(window application.Window) {
// Save file
window.EmitEvent("file:save", nil)
})

// Edit operations
app.KeyBinding.Add("Ctrl+Z", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+Z", func(window application.Window) {
// Undo
window.EmitEvent("edit:undo", nil)
})

app.KeyBinding.Add("Ctrl+Y", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+Y", func(window application.Window) {
// Redo (Windows/Linux)
window.EmitEvent("edit:redo", nil)
})

app.KeyBinding.Add("Cmd+Shift+Z", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Cmd+Shift+Z", func(window application.Window) {
// Redo (macOS)
window.EmitEvent("edit:redo", nil)
})
Expand Down Expand Up @@ -139,7 +139,7 @@ Remove key bindings when they're no longer needed:
app.KeyBinding.Remove("Ctrl+S")

// Example: Temporary key binding for a modal
app.KeyBinding.Add("Escape", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Escape", func(window application.Window) {
// Close modal
window.EmitEvent("modal:close", nil)
// Remove this temporary binding
Expand All @@ -165,7 +165,7 @@ for _, binding := range allBindings {
Make key bindings context-aware by checking application state:

```go
app.KeyBinding.Add("Ctrl+S", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+S", func(window application.Window) {
// Check current application state
if isEditMode() {
// Save document
Expand All @@ -184,7 +184,7 @@ app.KeyBinding.Add("Ctrl+S", func(window *application.WebviewWindow) {
Key bindings receive the active window, allowing window-specific behavior:

```go
app.KeyBinding.Add("F11", func(window *application.WebviewWindow) {
app.KeyBinding.Add("F11", func(window application.Window) {
// Toggle fullscreen for the active window
if window.Fullscreen() {
window.SetFullscreen(false)
Expand All @@ -193,7 +193,7 @@ app.KeyBinding.Add("F11", func(window *application.WebviewWindow) {
}
})

app.KeyBinding.Add("Ctrl+W", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+W", func(window application.Window) {
// Close the active window
window.Close()
})
Expand All @@ -206,15 +206,15 @@ Dynamically add and remove key bindings based on application state:
```go
func enableEditMode() {
// Add edit-specific key bindings
app.KeyBinding.Add("Ctrl+B", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+B", func(window application.Window) {
window.EmitEvent("format:bold", nil)
})

app.KeyBinding.Add("Ctrl+I", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+I", func(window application.Window) {
window.EmitEvent("format:italic", nil)
})

app.KeyBinding.Add("Ctrl+U", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+U", func(window application.Window) {
window.EmitEvent("format:underline", nil)
})
}
Expand Down Expand Up @@ -313,7 +313,7 @@ func disableEditMode() {

2. **Provide Visual Feedback**: Let users know when shortcuts are triggered:
```go
app.KeyBinding.Add("Ctrl+S", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+S", func(window application.Window) {
saveDocument()
// Show brief notification
window.EmitEvent("notification:show", "Document saved")
Expand All @@ -330,7 +330,7 @@ func disableEditMode() {

4. **Document Shortcuts**: Provide help or documentation for available shortcuts:
```go
app.KeyBinding.Add("F1", func(window *application.WebviewWindow) {
app.KeyBinding.Add("F1", func(window application.Window) {
// Show help dialog with available shortcuts
showKeyboardShortcutsHelp()
})
Expand All @@ -342,7 +342,7 @@ func disableEditMode() {
app.KeyBinding.Add("Escape", exitEditModeHandler)
}

func exitEditModeHandler(window *application.WebviewWindow) {
func exitEditModeHandler(window application.Window) {
exitEditMode()
app.KeyBinding.Remove("Escape") // Clean up temporary binding
}
Expand All @@ -367,33 +367,33 @@ func main() {

// File operations
if runtime.GOOS == "darwin" {
app.KeyBinding.Add("Cmd+N", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Cmd+N", func(window application.Window) {
window.EmitEvent("file:new", nil)
})
app.KeyBinding.Add("Cmd+O", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Cmd+O", func(window application.Window) {
openFile(app, window)
})
app.KeyBinding.Add("Cmd+S", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Cmd+S", func(window application.Window) {
window.EmitEvent("file:save", nil)
})
} else {
app.KeyBinding.Add("Ctrl+N", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+N", func(window application.Window) {
window.EmitEvent("file:new", nil)
})
app.KeyBinding.Add("Ctrl+O", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+O", func(window application.Window) {
openFile(app, window)
})
app.KeyBinding.Add("Ctrl+S", func(window *application.WebviewWindow) {
app.KeyBinding.Add("Ctrl+S", func(window application.Window) {
window.EmitEvent("file:save", nil)
})
}

// View operations
app.KeyBinding.Add("F11", func(window *application.WebviewWindow) {
app.KeyBinding.Add("F11", func(window application.Window) {
window.SetFullscreen(!window.Fullscreen())
})

app.KeyBinding.Add("F1", func(window *application.WebviewWindow) {
app.KeyBinding.Add("F1", func(window application.Window) {
showKeyboardShortcuts(window)
})

Expand All @@ -407,7 +407,7 @@ func main() {
}
}

func openFile(app *application.App, window *application.WebviewWindow) {
func openFile(app *application.App, window application.Window) {
dialog := app.Dialog.OpenFile()
dialog.AddFilter("Text Files", "*.txt;*.md")

Expand All @@ -416,7 +416,7 @@ func openFile(app *application.App, window *application.WebviewWindow) {
}
}

func showKeyboardShortcuts(window *application.WebviewWindow) {
func showKeyboardShortcuts(window application.Window) {
shortcuts := `
Keyboard Shortcuts:
- Ctrl/Cmd+N: New file
Expand All @@ -435,4 +435,4 @@ Test your key bindings on all target platforms to ensure they work correctly and

:::danger[Warning]
Be careful not to override critical system shortcuts. Some key combinations are reserved by the operating system and cannot be captured by applications.
:::
:::
1 change: 1 addition & 0 deletions v3/UNRELEASED_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ After processing, the content will be moved to the main changelog and this file
## Fixed
<!-- Bug fixes -->
- Prevent app crashing when calling systray.Run() before app.Run() by @leaanthony
- Update the docs page for keyboard shortcuts and corrects the type of the callback parameter for `KeyBinding.Add` by @ndianabasi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix parallel tense and add PR reference.

“Update … and corrects” mixes tenses; consider “Update … and correct …”. Also add the PR reference (e.g., #4829) per the file’s guidelines.

🔧 Suggested edit
-- Update the docs page for keyboard shortcuts and corrects the type of the callback parameter for `KeyBinding.Add` by `@ndianabasi`
+- Update the docs page for keyboard shortcuts and correct the type of the callback parameter for `KeyBinding.Add` (`#4829`) by `@ndianabasi`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Update the docs page for keyboard shortcuts and corrects the type of the callback parameter for `KeyBinding.Add` by @ndianabasi
- Update the docs page for keyboard shortcuts and correct the type of the callback parameter for `KeyBinding.Add` (`#4829`) by `@ndianabasi`
🤖 Prompt for AI Agents
In `@v3/UNRELEASED_CHANGELOG.md` at line 26, Edit the UNRELEASED_CHANGELOG.md
entry that currently reads "Update the docs page for keyboard shortcuts and
corrects the type of the callback parameter for `KeyBinding.Add` by `@ndianabasi`"
to use parallel tense and include the PR reference: change "corrects" to
"correct" so it reads "Update the docs page for keyboard shortcuts and correct
the type of the callback parameter for `KeyBinding.Add`" and append the PR
number in parentheses after the author (for example "by `@ndianabasi` (`#4829`)").


## Deprecated
<!-- Soon-to-be removed features -->
Expand Down
Loading