Skip to content

Commit 2cb5fc4

Browse files
small fixes to text width optimization
1 parent d1a5c0d commit 2cb5fc4

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

packages/builder-web-core/widgets-native/html-text-element/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ const __get_dedicated_element_tag = (t?: WebTextElement | undefined) => {
115115

116116
function textWH({ width, height }: { width: number; height: number }) {
117117
return {
118-
// TODO: do not specify width when parent is a flex container.
119-
// Also flex: 1 is required to make the text wrap.
118+
// TODO: do not specify width when parent is a flex container. (set as 100%)
119+
// Also flex-grow: 1 is required to make the text wrap.
120120
width: css.px(width),
121121
"min-height": css.px(height),
122122
};

packages/designto-token/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,14 @@ function handle_by_types(
273273
// FIXME: aberation handling (remove me if required) --------------------------------
274274
// FIXME: this is for giving extra space for text so it won't break line accidently.
275275
// FIXME: consider applying this only to a preview build
276-
if (node.data.length <= 6 && node.data.length > 2) {
276+
// TODO: change logic to word count.
277+
const wordcount = node.data.split(" ").length;
278+
const txtlen = node.data.length;
279+
if (wordcount <= 1) {
280+
/* skip, since there is no word break */
281+
} else if (txtlen <= 6 && wordcount <= 2) {
277282
node.width = node.width + 1;
278-
} else if (node.data.length < 30) {
283+
} else if (txtlen < 30) {
279284
node.width = node.width + 2;
280285
}
281286
// FIXME: ---------------------------------------------------------------------------------

packages/designto-token/token-layout/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ function find_original(ogchildren: Array<nodes.ReflectSceneNode>, of: Widget) {
250250
// target the unwrapped child
251251
c.id === (_unwrappedChild && _unwrappedChild.key.id) ||
252252
// target the widget itself - some widgets are not wrapped, yet being converted to a container-like (e.g. maskier)
253-
c.id === of.key.id
253+
c.id === of.key.id ||
254+
c.id === of.key.id.split(".")[0] // {id}.positioned or {id}.scroll-wrap TODO: this logic can cause problem later on.
254255
);
255256
if (!ogchild) {
256257
console.error(

0 commit comments

Comments
 (0)