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

Dropdown bar doesn't change when you move the cursor #29

Open
orblivion opened this issue Oct 5, 2021 · 4 comments
Open

Dropdown bar doesn't change when you move the cursor #29

orblivion opened this issue Oct 5, 2021 · 4 comments

Comments

@orblivion
Copy link

If you select and area and change the font, and then move your cursor away from that area, the dropdown bar stays on that font name. It's misleading since it looks like you'd be typing in that font in the area you just clicked on.

etherpad-lite tag 1.8.14, ep_font_family from npm

@JohnMcLear
Copy link
Member

Caret or cursor? I assume caret. This bug makes sense. Check ep_headings2 I think I wrote logic for that to make the select reflect the caret position.

@orblivion
Copy link
Author

Yes, caret, thank you. I did notice that this worked correctly with the headings plugin.

@JohnMcLear
Copy link
Member

You may (or may not) be able to port that logic over with a shift from line attribute to character attribute. That would be super cool. If you get stuck I'm happy to jump in. Oh, I wonder if ep_comments does caret position detection too for knowing which comment caret is currently on??

@orblivion
Copy link
Author

I looked at ep_headings2, but I realized that ep_font_color is a bit more pertinent since it goes by character rather than line, and it seemed like the behavior was correct. But then I saw this:

const startAttribs = attrManager.getAttributesOnPosition(rep.selStart[0], rep.selStart[1]);
const endAttribs = attrManager.getAttributesOnPosition(rep.selEnd[0], rep.selEnd[1]);
const [startColor] = startAttribs.filter((item) => item[0] === 'color');
const [endColor] = endAttribs.filter((item) => item[0] === 'color');
if (!startColor && !endColor) return;

If I select text that goes from red to green, it will short circuit the function and the dropdown will say "Font Size". However if my selection goes from red to green and back to red, startColor will equal endColor (despite the green in the middle) and the header will show up as "red". Seems like a bug. I'd like to avoid replicating it.

None of these attrManager.getAttribute* functions seem to be particularly well equipped to search for attributes across the entire selection. (getAttributeOnSelection just checks for whether the attribute exists somewhere in the selection).

The best I can figure out for how to do it correctly would be to iterate over getAttributesOnPosition for every selected position, but that's probably slow. Also, I don't know how many characters are in each line so I'm not sure how to iterate.

But, I'm looking at the implementation of getAttributesOnPosition for some insight.

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

No branches or pull requests

2 participants