-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Better block creation #24
base: master
Are you sure you want to change the base?
Conversation
@@ -20,3 +20,12 @@ browser.commands.onCommand.addListener((command) => { | |||
}).then((tabs) => | |||
tabs.forEach((tab) => browser.tabs.sendMessage(tab?.id!, command))); | |||
}); | |||
|
|||
browser.runtime.onMessage.addListener((command) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems to duplicate code above
import { Roam} from '../../utils/roam'; | ||
|
||
export const createDemo = async () => { | ||
await Roam.createBlockAtBottom(); | ||
Roam.writeText('bottom-block'); | ||
await Roam.createBlockAtBottom(false, 'bottom-block'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse the order of arguments to match other functions
}); | ||
}, | ||
|
||
async detectChange(fn: () => void, el?: HTMLElement){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe onChange
?
}, | ||
|
||
async detectChange(fn: () => void, el?: HTMLElement){ | ||
const targetNode = el || document.querySelector('.roam-body-main') as HTMLElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this work with the collapsed nodes?
isEmpty() { | ||
return !this.getActiveRoamNode()?.text; | ||
}, | ||
async addPlaceholder() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what is the placeholder stuff is for?
await this.selectBlock(); | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
detectChange
to confirm those actions. For now it just waits for any mutation aftersave
.