Skip to content

Commit

Permalink
QoL Improvements.
Browse files Browse the repository at this point in the history
Adding keyboard shortcut to create a new Card of the previous type. This shortcut is usable while typing in a description.
INTERNAL: Adding Shortcut.TempOverride. This is used to force a shortcut to be seen as being "pressed", even if that's not the case ordinarily.
FIX: Keybindings search area no longer accepts newlines.
  • Loading branch information
SolarLune committed Nov 6, 2023
1 parent c9eb523 commit 2af45ad
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ func placeCardInStack(card *Card, centerIfNoSelection bool) {
for _, t := range selection[0].Stack.Tail() {
t.Rect.Y += card.Rect.H
t.LockPosition()
globals.Project.UndoHistory.Capture(NewUndoState(t))
}
card.LockPosition()
globals.Project.Camera.FocusOn(false, card)
Expand Down
7 changes: 6 additions & 1 deletion gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,11 @@ func (label *Label) MoveCaretBackOneWord() int {

func (label *Label) Update() {

if label.Editing && globals.Keybindings.Pressed(KBNewCardOfPrevType) {
label.EndEditing()
return
}

clickedOut := false

if label.HorizontalAlignment == AlignCenter {
Expand Down Expand Up @@ -1793,7 +1798,7 @@ func (label *Label) Update() {
}

// Typing
if len(globals.InputText) > 0 {
if !clickedOut && len(globals.InputText) > 0 {
label.DeleteSelectedChars()
label.InsertRunesAtIndex(globals.InputText, label.Selection.CaretPos)
label.Selection.AdvanceCaret(len(globals.InputText))
Expand Down
14 changes: 10 additions & 4 deletions keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const (
KBPasteText = "Textbox: Paste Copied Text"
KBSelectAllText = "Textbox: Select All Text"

KBSwitchWrapMode = "Card Text Editing: Switch Wrap Mode"
KBSwitchWrapMode = "Card Text Editing: Switch Wrap Mode"
KBNewCardOfPrevType = "Create New Card of Prev. Type"

KBUndo = "Undo"
KBRedo = "Redo"
Expand Down Expand Up @@ -219,8 +220,9 @@ type Shortcut struct {
triggerMode int
MouseButton uint8
DefaultMouseButton uint8
DefaultSet bool

DefaultSet bool
TempOverride bool
}

func NewShortcut(name string) *Shortcut {
Expand Down Expand Up @@ -396,7 +398,6 @@ func NewKeybindings() *Keybindings {
MouseShortcutsByFamily: map[uint8][]*Shortcut{},
}
kb.Default()
kb.UpdateShortcutFamilies()
return kb
}

Expand Down Expand Up @@ -482,6 +483,7 @@ func (kb *Keybindings) Default() {
kb.DefineKeyShortcut(KBNewSubpageCard, sdl.K_8, sdl.K_LSHIFT)
kb.DefineKeyShortcut(KBNewLinkCard, sdl.K_9, sdl.K_LSHIFT)
kb.DefineKeyShortcut(KBNewTableCard, sdl.K_0, sdl.K_LSHIFT)
kb.DefineKeyShortcut(KBNewCardOfPrevType, sdl.K_RETURN, sdl.K_LCTRL)

kb.DefineKeyShortcut(KBAddToSelection, sdl.K_LSHIFT).triggerMode = TriggerModeHold
kb.DefineKeyShortcut(KBRemoveFromSelection, sdl.K_LALT).triggerMode = TriggerModeHold
Expand Down Expand Up @@ -513,7 +515,7 @@ func (kb *Keybindings) Default() {

kb.DefineKeyShortcut(KBWindowSizeSmall, sdl.K_F9)
kb.DefineKeyShortcut(KBWindowSizeNormal, sdl.K_F10)
kb.DefineKeyShortcut(KBToggleFullscreen, sdl.K_RETURN, sdl.K_LCTRL)
kb.DefineKeyShortcut(KBToggleFullscreen, sdl.K_RETURN, sdl.K_LALT)
kb.DefineKeyShortcut(KBUnlockImageASR, sdl.K_LSHIFT).triggerMode = TriggerModeHold

kb.DefineKeyShortcut(KBCheckboxToggleCompletion, sdl.K_SPACE)
Expand Down Expand Up @@ -619,6 +621,10 @@ func (kb *Keybindings) Pressed(bindingName string) bool {
return false
}

if sc.TempOverride {
return true
}

if sc.MouseButton < 255 {

for _, familyShortcut := range kb.MouseShortcutsByFamily[sc.MouseButton] {
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ func main() {

HandleFontReload()

for _, s := range globals.Keybindings.Shortcuts {
s.TempOverride = false
}

}

if globals.Settings.Get(SettingsSaveWindowPosition).AsBool() {
Expand Down Expand Up @@ -2449,6 +2453,8 @@ where the cursor is over the window.`))
row.Add("search label", NewLabel("Search: ", nil, false, AlignLeft))
searchKeybindingsLabel := NewLabel("test", &sdl.FRect{0, 0, 380, 32}, false, AlignLeft)
searchKeybindingsLabel.Editable = true
searchKeybindingsLabel.RegexString = RegexNoNewlines

// searchKeybindingsLabel.AutoExpand = true
searchKeybindingsLabel.OnChange = func() {

Expand Down
17 changes: 17 additions & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,23 @@ func (project *Project) GlobalShortcuts() {

}

if kb.Pressed(KBNewCardOfPrevType) && (globals.State == StateNeutral || globals.State == StateMapEditing || globals.State == StateTextEditing) {
newCard := project.CurrentPage.CreateNewCard(project.LastCardType)
kb.Shortcuts[KBNewCardOfPrevType].ConsumeKeys()
placeCardInStack(newCard, false)
project.CurrentPage.Selection.Clear()
project.CurrentPage.Selection.Add(newCard)

// Trigger text editing for this new card and update it by triggering all possible shortcuts for text editing. TODO: Clean this up.
kb.Shortcuts[KBCheckboxEditText].TempOverride = true
kb.Shortcuts[KBLinkEditText].TempOverride = true
kb.Shortcuts[KBNoteEditText].TempOverride = true
kb.Shortcuts[KBNumberedEditText].TempOverride = true
kb.Shortcuts[KBTimerEditText].TempOverride = true
kb.Shortcuts[KBSubpageEditText].TempOverride = true
newCard.Update()
}

if globals.State == StateNeutral || globals.State == StateMapEditing || globals.State == StateCardArrow {

kb := globals.Keybindings
Expand Down
11 changes: 10 additions & 1 deletion todo
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
[x] Editing card pushes lower cards up
[x] Taking screenshots crash MP
[x] Can't go up sub-pages via keybinding while in Link Mode

[ ] Deleting cards should move the rest of the cards up (new shortcut?)
[ ] Show shortcut collisions in input menu
[ ] Give message on start-up when there's a shortcut collision
[ ] Link text is essentially blank
[ ] AMD cards might have minor graphical glitches? Mainly in main menu
[ ] Investigate web - maybe I can render a website to an image and then link to it? - chromedp to have an actual visible website?
[ ] State testing could be drastically simplified
[ ] Consolidate card contents text editing (see project.go:1348)

[ ] AMD cards might have MAJOR graphical glitches? Mainly in main menu
[ ] Menu shadows are way too dark

[x] It does not like cutting and pasting a sub-card into itself.
Expand Down Expand Up @@ -84,6 +92,7 @@
[x] Make it so if images surpass the GPU's maximum texture size, they get sized down
[x] What should we do if we're using media from another drive?
[ ] Optimize - seems like there's a memory leak somewhere
[ ] Loop through slices to perform a function instead of making a duplicate slice to iterate through
[ ] Show keybinding conflicts in the Keybindings menu
[x] Make all text fields in Cards (like their title / description) consistent in terms of their capabilities
[ ] Fix storing a card in collapsed mode doesn't allow it to become uncollapsed; guess we'll need to store the uncollapsed size to revert to.
Expand Down

0 comments on commit 2af45ad

Please sign in to comment.