Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Better block creation #24

wants to merge 9 commits into from

Conversation

dalmo3
Copy link
Contributor

@dalmo3 dalmo3 commented Feb 29, 2020

#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
@@ -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) => {
Copy link
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

import { Roam} from '../../utils/roam';

export const createDemo = async () => {
await Roam.createBlockAtBottom();
Roam.writeText('bottom-block');
await Roam.createBlockAtBottom(false, 'bottom-block');
Copy link
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

});
},

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

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;
Copy link
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?

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
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

const thisBlock = this.getRoamBlockInput() as HTMLElement;
return thisBlock === DOM.getLastSibling(thisBlock)
},
async goToParent() {
Copy link
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?

const thisBlock = this.getRoamBlockInput() as HTMLElement;
return this.activateBlock(DOM.getBlockParent(thisBlock))
},
async goToFirstChild() {
Copy link
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?

isEmpty() {
return !this.getActiveRoamNode()?.text;
},
async addPlaceholder() {
Copy link
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?

await this.selectBlock();
await Keyboard.simulateKey(Keyboard.RIGHT_ARROW);
await Keyboard.pressEnter();
await this.createSiblingBelow();
if (text) await this.writeText(text);
Copy link
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

};

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
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
Copy link
Member

Stvad commented Mar 21, 2020

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