Better block creation - #24
Conversation
| tabs.forEach((tab) => browser.tabs.sendMessage(tab?.id!, command))); | ||
| }); | ||
|
|
||
| browser.runtime.onMessage.addListener((command) => { |
| export const createDemo = async () => { | ||
| await Roam.createBlockAtBottom(); | ||
| Roam.writeText('bottom-block'); | ||
| await Roam.createBlockAtBottom(false, 'bottom-block'); |
There was a problem hiding this comment.
reverse the order of arguments to match other functions
| }); | ||
| }, | ||
|
|
||
| async detectChange(fn: () => void, el?: HTMLElement){ |
| }, | ||
|
|
||
| async detectChange(fn: () => void, el?: HTMLElement){ | ||
| const targetNode = el || document.querySelector('.roam-body-main') as HTMLElement; |
There was a problem hiding this comment.
make it a default parameter value?
| const targetNode = el || document.querySelector('.roam-body-main') as HTMLElement; | ||
| const config = { attributes: true, childList: true, subtree: true }; | ||
| return new Promise(async resolve => { | ||
| //@ts-ignore unused arg |
There was a problem hiding this comment.
you can just name it _ , also I'd probably inline callback
| const thisBlock = this.getRoamBlockInput() as HTMLElement; | ||
| return thisBlock === DOM.getLastSibling(thisBlock) | ||
| }, | ||
| async goToParent() { |
There was a problem hiding this comment.
activate instead of goTo in all these functions?
| const thisBlock = this.getRoamBlockInput() as HTMLElement; | ||
| return this.activateBlock(DOM.getBlockParent(thisBlock)) | ||
| }, | ||
| async goToFirstChild() { |
There was a problem hiding this comment.
does this work with the collapsed nodes?
| isEmpty() { | ||
| return !this.getActiveRoamNode()?.text; | ||
| }, | ||
| async addPlaceholder() { |
There was a problem hiding this comment.
I'm not sure what is the placeholder stuff is for?
| await Keyboard.simulateKey(Keyboard.RIGHT_ARROW); | ||
| await Keyboard.pressEnter(); | ||
| await this.createSiblingBelow(); | ||
| if (text) await this.writeText(text); |
There was a problem hiding this comment.
I think you should move the check for text validity inside the writeText function instead of always gating it
|
|
||
| export class RoamNode { | ||
| constructor(readonly text: string, readonly selection: Selection) { | ||
| constructor(readonly text: string, readonly selection: Selection = new Selection(text.length,text.length)) { |
There was a problem hiding this comment.
why the end and not the beginning?
|
I think this can be improved with the new ability to query the db directly (specifically querying for children/etc) |
#19 failed to account for many edge cases. Especially regarding empty blocks - just pressing the same keys would give wildly different results.
Needed to add a series of DOM functions to find a block's surroundings. Caveat: rebuilt dom.js and it now needs to be imported as an object elsewhere.
Also first experiments with
detectChangeto confirm those actions. For now it just waits for any mutation aftersave.