Skip to content

Commit

Permalink
Ignore text insertion cursor when previewing markdown (stevencohn#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored and weissm committed Jul 9, 2024
1 parent 4abf91f commit f521112
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions OneMore/Models/PageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ public async Task<XElement> ExtractSelectedContent()
(AllContent || e.Attributes().Any(a => a.Name == "selected" && a.Value == "all")))
.ToList();

if (runs.Any() && AllContent)
{
// filter out the blank cursor to avoid inadvertently inserting a newline
runs = runs.Except(runs.Where(e =>
e.Attributes().Any(a => a.Name == "selected" && a.Value == "all") &&
e.GetCData().Value == string.Empty))
.ToList();
}

// no selections found in body
if (!runs.Any())
{
Expand Down
5 changes: 5 additions & 0 deletions OneMore/Models/PageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public string GetSelectedText(bool withTitle = true)
/// <returns></returns>
public string ReadTextFrom(IEnumerable<XElement> paragraphs, bool allText)
{
if (!paragraphs.Any())
{
return string.Empty;
}

var builder = new StringBuilder();

foreach (var paragraph in paragraphs)
Expand Down

0 comments on commit f521112

Please sign in to comment.