-
-
Notifications
You must be signed in to change notification settings - Fork 3k
impr: enable dots typed effect for ligature languages (@byseif21) #7458
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
base: master
Are you sure you want to change the base?
Changes from all commits
c1bdd6c
a6cddd2
e830566
709adbb
b539944
8caa019
eed55cb
e051784
32694a1
aae08c9
6760d2b
b2d8d2c
5b72288
e6cf966
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import Config from "../config"; | ||
| import { ElementWithUtils } from "../utils/dom"; | ||
|
|
||
| function canBreak(wordEl: ElementWithUtils): boolean { | ||
| if (Config.typedEffect !== "dots") return false; | ||
| if (wordEl.hasClass("broken-ligatures")) return false; | ||
|
|
||
| return !!wordEl.native.closest(".withLigatures"); | ||
| } | ||
|
|
||
| function applyIfNeeded(wordEl: ElementWithUtils): void { | ||
| if (!canBreak(wordEl)) return; | ||
|
|
||
| const { width } = wordEl.screenBounds(); | ||
| wordEl.setStyle({ width: `${width}px` }); | ||
| wordEl.addClass("broken-ligatures"); | ||
| } | ||
|
|
||
| function reset(wordEl: ElementWithUtils): void { | ||
| if (!wordEl.hasClass("broken-ligatures")) return; | ||
| wordEl.removeClass("broken-ligatures"); | ||
| wordEl.setStyle({ width: "" }); | ||
| } | ||
|
|
||
| export function set( | ||
| wordEl: ElementWithUtils, | ||
| areLigaturesBroken: boolean, | ||
| ): void { | ||
| areLigaturesBroken ? applyIfNeeded(wordEl) : reset(wordEl); | ||
| } | ||
|
|
||
| export function update(key: string, wordsEl: ElementWithUtils): void { | ||
| const words = wordsEl.qsa(".word.typed"); | ||
|
|
||
| const shouldReset = | ||
| !wordsEl.hasClass("withLigatures") || | ||
| Config.typedEffect !== "dots" || | ||
| key === "fontFamily" || | ||
| key === "fontSize"; | ||
|
|
||
| if (shouldReset) { | ||
| words.forEach(reset); | ||
| } | ||
| words.forEach(applyIfNeeded); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if ok? or heavy and should we do batching instead?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd do this: (not tested)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i meant performance wise
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance wise we're running on the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think about batching then? too much or worth it?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say it's worth it. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ import * as SlowTimer from "../states/slow-timer"; | |
| import * as TestConfig from "./test-config"; | ||
| import * as CompositionDisplay from "../elements/composition-display"; | ||
| import * as AdController from "../controllers/ad-controller"; | ||
| import * as Ligatures from "./break-ligatures"; | ||
| import * as LayoutfluidFunboxTimer from "../test/funbox/layoutfluid-funbox-timer"; | ||
| import * as Keymap from "../elements/keymap"; | ||
| import * as ThemeController from "../controllers/theme-controller"; | ||
|
|
@@ -141,6 +142,7 @@ export function updateActiveElement( | |
| if (previousActiveWord !== null) { | ||
| if (direction === "forward") { | ||
| previousActiveWord.addClass("typed"); | ||
| Ligatures.set(previousActiveWord, true); | ||
| } else if (direction === "back") { | ||
| // | ||
| } | ||
|
|
@@ -157,6 +159,7 @@ export function updateActiveElement( | |
| newActiveWord.addClass("active"); | ||
| newActiveWord.removeClass("error"); | ||
| newActiveWord.removeClass("typed"); | ||
| Ligatures.set(newActiveWord, false); | ||
|
|
||
| activeWordTop = newActiveWord.getOffsetTop(); | ||
| activeWordHeight = newActiveWord.getOffsetHeight(); | ||
|
|
@@ -2072,11 +2075,15 @@ ConfigEvent.subscribe(({ key, newValue }) => { | |
| "colorfulMode", | ||
| "showAllLines", | ||
| "fontSize", | ||
| "fontFamily", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now run
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the thing is I think I still need some of the layout updates it triggers when fontFamily changes. I’ll give it some manual testing to see
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kinda feel like |
||
| "maxLineWidth", | ||
| "tapeMargin", | ||
| ].includes(key) | ||
| ) { | ||
| updateWordWrapperClasses(); | ||
| if (key !== "fontFamily") updateWordWrapperClasses(); | ||
| if (["typedEffect", "fontFamily", "fontSize"].includes(key)) { | ||
| Ligatures.update(key, wordsEl); | ||
| } | ||
| } | ||
| if (["tapeMode", "tapeMargin"].includes(key)) { | ||
| updateLiveStatsMargin(); | ||
|
|
||
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.
Consider replacing with this:
return wordEl.getParent().hasClass("withLigatures");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?
closestfaster and better,getParent()creates a newElementWithUtilsobject wrapper every single timeUh oh!
There was an error while loading. Please reload this page.
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.
closestseems less readable, as it doesn't make it clear what element might have thewithLigaturesclass. Also (it might just be me), but I really hate the!!syntax.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.
let's do the spin
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 lost, so keep current approach.