Link Search Menu Expand Document

Internal

Summary

This describes the logic for Note Lookup

State Diagram

stateDiagram-v2 [*] --> LookupCommand state LookupCommand { [*] --> run run --> gatherInput gatherInput --> prepareQuickPick gatherInput --> constructProvider gatherInput --> enrichInput enrichInput --> subscribe enrichInput --> subscribedToListener subscribedToListener --> showQuickPick lookupExecute --> [*] state Controller { prepareQuickPick prepareQuickPick --> gatherInput showQuickPick --> onUpdatePickerItems showQuickPick --> [*] } state Provider { constructProvider --> gatherInput onUpdatePickerItems --> updatePickerItems } state Quickpick { state updatePickerItems <> updatePickerItems --> fetchRootResults: if qs = "" updatePickerItems --> [*]: if noChangeValue(picker) updatePickerItems --> fetchPickerResultsp fetchRootResults --> [*] } } state HistoryListener { state listen <> subscribe --> listening listening --> listen listen --> done : if action = done listen --> done : if action = changeState & data = hide & !picker.pending listen --> done : if action = error listen --> listening: otherwise done --> [*] } HistoryListener --> lookupExecute

Steps

  • Gather Input
  • enrichInput
    • show QuickPick
  • showQuickPick
    • updatePickerItems
    • if noConfirm, don't show widget
      • update selected items to current current items
      • call provider.onDidAccept
    • else show the widget
      • wait until user accepts or cancels
  • execute

Code

Gather Input

  • src/commands/NoteLookupCommand.ts
gatherInputs {
    lc = this._controller = LookupControllerV3.create
    this._provider = new NoteLookupProvider("lookup", {
    lc.prepareQuickPick
}

Prepare Quickpick

  • src/components/lookup/LookupControllerV3.ts
prepareQuickPick {
    quickpick.onTriggerButton = @onDidTriggerButton
    refreshButtons
}

showQuickPick {
    provider.onUpdatePickerItems 

}

OnDidTriggerButton

onDidTriggerButton(btn) {
    find(btn, @state.buttons).pressed = btn.pressed
    refreshPickerBehavior(@state.buttons)
}

RefreshPickerBehavior

refreshPickerBehavior {
    buttonsEnabled :=
    buttonsDisabled :=

    buttonsEnabled.map bt => bt.onEnable
    buttonsDisabled.map bt => bt.onDisable
}

OnUpdatePickerItems

onUpdatePickerItems {

    // modify for just activated behavior
    if picker.justActivated && !picker.nonInteractive  {
        pickerValue = getQsForCurrentLevel
    }
    querystring := pickerValue
    ...
    items = [...picker.items]
    updatedItems = fetchPickerResults(querystring)
    ...
    picker.items = updatedItems

}

OnAccept

  • src/components/lookup/LookupProviderV3.ts
onDidAccept {
    selectedItems := picker
    resp = @_onAcceptHooks.map {
        it(picker, selectedItems)
    }

    HistoryInstance.add {
        source: lookupProvider,
        action: done,
        id: @id,
        data: {
            selectedItems,
            onAcceptHookResp: resp
        }
    }

}
execute {
    @acceptItem
}

acceptItem(item, picker) {

    throw if not picker.validate(item)

    if isNew(item) {
        @acceptNewItem
    } else {
        @acceptExistingItem
    }
}

acceptExistingItem {
    uri := item
    show uri
}

acceptNewItem(item, picker) {
    fname := picker
    if isStub(item) {
        note = notes[item.stub]
        delete note.stub
    } else {
        note = Note.create item
        if matchSchema(note) {
            addSchema(note)
        }
        if note.schema.template {
            applyTemplate(note)
        }
    }
    note = picker.transformTitle(note)
    picker.onCreate(note)
    writeNote note
}

Design Decisions

Debounce


Children

  1. Create New Note
  2. Old