Skip to content

Better block creation - #24

Open
dalmo3 wants to merge 9 commits into
masterfrom
better-block-creation
Open

Better block creation#24
dalmo3 wants to merge 9 commits into
masterfrom
better-block-creation

Conversation

@dalmo3

@dalmo3 dalmo3 commented Feb 29, 2020

Copy link
Copy Markdown
Contributor

#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 after save.

@dalmo3
dalmo3 requested a review from Stvad February 29, 2020 00:03
tabs.forEach((tab) => browser.tabs.sendMessage(tab?.id!, command)));
});

browser.runtime.onMessage.addListener((command) => {

Copy link
Copy Markdown
Member

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

export const createDemo = async () => {
await Roam.createBlockAtBottom();
Roam.writeText('bottom-block');
await Roam.createBlockAtBottom(false, 'bottom-block');

Copy link
Copy Markdown
Member

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

Comment thread src/ts/utils/dom.ts
});
},

async detectChange(fn: () => void, el?: HTMLElement){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe onChange?

Comment thread src/ts/utils/dom.ts
},

async detectChange(fn: () => void, el?: HTMLElement){
const targetNode = el || document.querySelector('.roam-body-main') as HTMLElement;

Copy link
Copy Markdown
Member

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?

Comment thread src/ts/utils/dom.ts
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

Copy link
Copy Markdown
Member

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

Comment thread src/ts/utils/roam.ts
const thisBlock = this.getRoamBlockInput() as HTMLElement;
return thisBlock === DOM.getLastSibling(thisBlock)
},
async goToParent() {

Copy link
Copy Markdown
Member

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?

Comment thread src/ts/utils/roam.ts
const thisBlock = this.getRoamBlockInput() as HTMLElement;
return this.activateBlock(DOM.getBlockParent(thisBlock))
},
async goToFirstChild() {

Copy link
Copy Markdown
Member

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?

Comment thread src/ts/utils/roam.ts
isEmpty() {
return !this.getActiveRoamNode()?.text;
},
async addPlaceholder() {

Copy link
Copy Markdown
Member

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?

Comment thread src/ts/utils/roam.ts
await Keyboard.simulateKey(Keyboard.RIGHT_ARROW);
await Keyboard.pressEnter();
await this.createSiblingBelow();
if (text) await this.writeText(text);

Copy link
Copy Markdown
Member

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

Comment thread src/ts/utils/roam.ts

export class RoamNode {
constructor(readonly text: string, readonly selection: Selection) {
constructor(readonly text: string, readonly selection: Selection = new Selection(text.length,text.length)) {

Copy link
Copy Markdown
Member

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?

@Stvad

Stvad commented Mar 21, 2020

Copy link
Copy Markdown
Member

I think this can be improved with the new ability to query the db directly (specifically querying for children/etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants