Repository navigation
Fix typed Markdown and links on new notes #613
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ pub struct InlineEdit { | |
| spans: Vec<Span>, | ||
| text: String, | ||
| literal: Vec<bool>, | ||
| /// The surrounding style to resume when typing after a just-closed Markdown run. | ||
| trailing_style: Option<Span>, | ||
| /// True while `spans`/`text` are the caret's view: the tag marker was taken off the | ||
| /// front and goes back on when the block is written. | ||
| caret: bool, | ||
|
|
@@ -198,7 +200,7 @@ pub(super) fn link_span(spans: &[Span], at: usize) -> Option<(usize, usize, Stri | |
| impl InlineEdit { | ||
| pub(super) fn from_spans(spans: &[Span]) -> Self { | ||
| let text = visible_text(spans); | ||
| Self { spans: spans.to_vec(), literal: vec![true; text.chars().count()], text, caret: false } | ||
| Self { spans: spans.to_vec(), literal: vec![true; text.chars().count()], text, trailing_style: None, caret: false } | ||
| } | ||
|
|
||
| pub(super) fn new(block: &Block, caret: bool) -> Self { | ||
|
|
@@ -299,8 +301,8 @@ impl InlineEdit { | |
| let fresh = matched.len() * 2 < old_run.len(); | ||
| // Where the run lands: the span holding its first character, for inherited style. | ||
| let mut at = 0usize; | ||
| let mut donor = None; | ||
| if !whole { | ||
| let mut donor = self.trailing_style.take().filter(|_| prefix == old_chars.len()); | ||
| if donor.is_none() && !whole { | ||
| for (index, span) in self.spans.iter().enumerate() { | ||
| let len = visible_len(span); | ||
| if run_start < at + len || (run_start == at + len && index + 1 == self.spans.len()) { | ||
|
|
@@ -351,6 +353,9 @@ impl InlineEdit { | |
| } | ||
| } | ||
| let fragment = parse_inline(&projected); | ||
| // A styled run produced by wrapping existing words (such as a ribbon font choice) | ||
| // remains the typing style. Resume the donor only after completing markup by appending. | ||
| let closed_at_end = prefix == old_chars.len() && fragment.last().is_some_and(|span| !plain(span)); | ||
| let mut spans = take_spans(&self.spans, 0..run_start); | ||
| let mut literal = self.literal[..run_start.min(self.literal.len())].to_vec(); | ||
| for span in fragment { | ||
|
|
@@ -419,6 +424,9 @@ impl InlineEdit { | |
| spans.extend(take_spans(&self.spans, run_end..usize::MAX)); | ||
| literal.extend_from_slice(&self.literal[run_end.min(self.literal.len())..]); | ||
| self.adopt_with_literal(spans, literal); | ||
| if closed_at_end { | ||
| self.trailing_style = Some(Span { text: String::new(), ..donor.unwrap_or_default() }); | ||
|
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. Make the collapsed-caret style queries match the style that typing will use. After While the saved trailing style applies, the collapsed-caret font and style queries must report the style that the next typed character receives. The saved style applies only at the end of the text, where The fix can change the queries, the saved state, or both. The inspected code does not establish which choice is correct, so this comment does not prescribe one. Affected locations
|
||
| } | ||
| self.spans.clone() | ||
| } | ||
|
|
||
|
|
@@ -430,6 +438,7 @@ impl InlineEdit { | |
| literal = vec![true; self.text.chars().count()]; | ||
| } | ||
| self.literal = literal; | ||
| self.trailing_style = None; | ||
| } | ||
|
|
||
| /// The serialized-source entry point kept for callers that still hand over `block_text`: | ||
|
|
@@ -477,14 +486,15 @@ impl InlineEdit { | |
| let spans = take_spans(&self.spans, range.clone()); | ||
| let text = visible_text(&spans); | ||
| let literal = self.literal.get(range.start..range.end).map(<[bool]>::to_vec).unwrap_or_else(|| vec![true; text.chars().count()]); | ||
| Self { spans, text, literal, caret: self.caret } | ||
| Self { spans, text, literal, trailing_style: None, caret: self.caret } | ||
| } | ||
|
|
||
| pub(super) fn join(&mut self, other: Self) { | ||
| self.spans.extend(other.spans); | ||
| self.spans = merge(std::mem::take(&mut self.spans)); | ||
| self.text = visible_text(&self.spans); | ||
| self.literal.extend(other.literal); | ||
| self.trailing_style = None; | ||
| if self.literal.len() != self.text.chars().count() { | ||
| self.literal = vec![true; self.text.chars().count()]; | ||
| } | ||
|
|
@@ -499,6 +509,7 @@ impl InlineEdit { | |
| } | ||
| self.spans = merge(spans); | ||
| self.text = visible_text(&self.spans); | ||
| self.trailing_style = None; | ||
| Some((self.text.clone(), selection)) | ||
| } | ||
|
|
||
|
|
@@ -510,6 +521,7 @@ impl InlineEdit { | |
| } | ||
| self.spans = merge(spans); | ||
| self.text = visible_text(&self.spans); | ||
| self.trailing_style = None; | ||
| Some((self.text.clone(), selection)) | ||
| } | ||
|
|
||
|
|
||
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.
Exclude an existing date caret from the link target.
On a new note, Escape in the title field can place the caret in the date paragraph through
page_title. The new predicate skips caret placement but retains that existing caret. Confirmation then callsreplace_in_caret_line, so the link enters the date paragraph instead of a body paragraph below it.Treat a date-only target as the append case, while preserving ordinary body selections. Add the title-Escape sequence to the new-page test.