The TextAffinity enum in Flutter has the following documentation description:
A way to disambiguate a TextPosition when its offset could match two
different locations in the rendered string.
For example, at an offset where the rendered text wraps, there are two
visual positions that the offset could represent: one prior to the
line break (at the end of the first line) and one after the line break
(at the start of the second line). A text affinity disambiguates
between these two cases.
This affects only line breaks caused by wrapping, not explicit newline
characters. For newline characters, the position is fully specified by
the offset alone, and there is no ambiguity.
TextAffinity also affects bidirectional text at the interface between
LTR and RTL text. Consider the following string, where the lowercase
letters will be displayed as LTR and the uppercase letters RTL:
"helloHELLO". When rendered, the string would appear visually as
"helloOLLEH". An offset of 5 would be ambiguous without a
corresponding TextAffinity. Looking at the string in code, the offset
represents the position just after the "o" and just before the "H".
When rendered, this offset could be either in the middle of the string
to the right of the "o" or at the end of the string to the right of
the "H".
This kind of makes sense but it's still a little confusing. For example "helloHELLO" isn't actually bidirectional text. How is offset 5 ambiguous? Do you have a visual example?
I'm adding my answer below.
TextAffinity disambiguates text position for soft wraps and bidirectional text boundaries. The affinity can be either upstream or downstream. Downstream is the default.
Soft wrap position
Given the string 0123456789 whose last character soft-wraps to the next line, you can choose the cursor position as follows. Both positions are at offset 9:
Downstream
Upstream
Bidirectional text boundary
Given the string Helloשלום where Hello is LRT text and שלום is RTL text, you can choose the cursor position at the boundary between them as follows. Both positions are at offset 5:
Downstream
Upstream
Going on
I write about this in more detail here.
Related
I have a string of text that dynamically resizes. At its core its basically a Text widget in a SizedBox in a Column.
When it resizes, the words wrap to the next as you typically expect...it breaks to the next line by using the 'SPACES' between words (as opposed to breaking up words character by character).
However, an email address can be a very long string without spaces. When it no longer fits within the bounds of the box it begins to resize itself by breaking on individual characters and moving into the next line.
It's a minor issue, but not visually appealing.
How might one create breakpoints within the String to resize itself by wrapping to the next line based on custom characters? For example, in an email address I'd prefer it break on the '#' and/or '.' before resorting to breaking up the String on individual characters.
I am trying to display text over time using altair (vega-lite), which works fine using a layered chart, where one is created using the alt.Chart().mark_text() function to display the text.
The text though is multiple phrases and should be wrapped (with line breaks). How can this be done?
(I do not want to use fixed line breaks, e.g. \n, at distinct positions since the text wrapping should work with zooming too)
Not exactly what you want, but you can specify a character on which to break to a new line. When zooming, the text stays the same size, so it should always fit the view.
For example making a new line for every word:
.mark_text(lineBreak=' ')
I am trying to simulate Word's displaying of non-printing characters. There is no problem with all of them but anchors and I didn't found any info related to them. Is anchor special character placed in text or is it parameter of floating object and just displayed as special character?
Thank you for answer
The anchor, unlike most non-printing characters, can never print. It's merely a visual aid to inform the user with which paragraph or character a graphic with text flow formatting is associated. It's not possible to detect an anchor directly in the document text using Word's API (object model). It's bound to the graphic and would require analyzing the properties of the Shape object.
It could be determined by analyzing the document's WordOpenXML, although the term "anchor" is not used. The information could be deduced from the location and settings of the nodes that define where and how the graphic appears.
Is anchor special character placed in text or is it parameter of floating object and just displayed as special character?
I'm going to try to answer the "is it in text" question.
If, while debugging, you try to get a textual character for an anchor from a range's text, it won't be there. There won't even be a 0-width non-visible character there, like when you move a text cursor to the right past a non-printable character, but it doesn't actually move because there's something there (this may be editor-dependent, I have Notepad++ in mind).
So no, it's not in text.
But, at the same time, it will interfere with searches. E.g. If you put the word "text" on a line, put a text box on that line to create an anchor, and then search for "^13text" (with wildcards enabled, ^13 means the end-of-paragraph mark), it won't find it.
So yes, it must be in text because it interferes with searches.
So this might be a contradiction, but let's keep going. If it's in text, where is it? If you place the text cursor on the previous line, hold shift, and move it once to the right, the text box will be highlighted.
So it must be at the start.
But, there is also evidence that contradicts this. If you have a field at the start of the line with text on it, you can move it once to the right as before, and then once to the left, and though you have part of the line highlighted, the text box won't be part of the selection.
So, I really have no idea whether it's text or not, or where it is if so, but hopefully this helps someone else.
When using Emacs's text mode, I find it handy to use the default indentation method with below features:
When I am at some indentation level, hitting C-j
will automatically bring me to the next line with identical
indentation level
When I hit Tab, the indentation will further right by some amount (usually to align with the next word in previous line)
However, I find it difficult to go back by one indentation level. E.g. If the current cursor is at the position of | as below:
Line 0: some text here
Line 1: some text here
Line 2: some text here
|Line 3: some text here
what can I do to bring the cursor to align with "L" in line 1?
Note the amount of spaces of each level indentation is not fixed, as it is usually align to the 2nd word of previous line. So it seems not proper to use reducing 4-spaces as indent to previous level.
Just curious whether there is any predefined / customized function for such purpose. It seems natural to seek for a corresponding "left-indent" command if the text-editor already provides a "right-indent" one.
How can I make Emacs automatically wrap lines of text that I've already written such that no line is longer than, say, 70 characters. In other words, I'd like to do "auto-fill-mode" after-the-fact.
Is this possible?
Look at fill-paragraph and fill-region. If I remember correctly, it's bound to M-q by default. To set the line width, use C-xf.
In addition to fill-paragraph and fill-region, take a look at these commands:
file-individual-paragraphs: "Fill paragraphs of uniform indentation within the region.
This command divides the region into "paragraphs",
treating every change in indentation level or prefix as a paragraph boundary,
then fills each paragraph using its indentation level as the fill prefix.
There is one special case where a change in indentation does not start
a new paragraph. This is for text of this form:
foo> This line with extra indentation starts
foo> a paragraph that continues on more lines.
These lines are filled together."
fill-nonuniform-paragraphs: "Fill paragraphs within the region, allowing varying indentation within each.
This command divides the region into "paragraphs",
only at paragraph-separator lines, then fills each paragraph
using as the fill prefix the smallest indentation of any line
in the paragraph."