Skip to content

Commit badde02

Browse files
author
ArthurHub
committed
* add SelectedText, SelectedHtml to get selected text/html.
1 parent a75a778 commit badde02

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

‎Source/HtmlRenderer/Handlers/SelectionHandler.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,22 @@ public void CopySelectedHtml()
306306
}
307307
}
308308

309+
/// <summary>
310+
/// Get the currently selected text segment in the html.<br/>
311+
/// </summary>
312+
public string GetSelectedText()
313+
{
314+
return _root.HtmlContainer.IsSelectionEnabled ? DomUtils.GetSelectedPlainText(_root) : null;
315+
}
316+
317+
/// <summary>
318+
/// Copy the currently selected html segment with style.<br/>
319+
/// </summary>
320+
public string GetSelectedHtml()
321+
{
322+
return _root.HtmlContainer.IsSelectionEnabled ? DomUtils.GenerateHtml(_root, HtmlGenerationStyle.Inline, true) : null;
323+
}
324+
309325
/// <summary>
310326
/// The selection start index if the first selected word is partially selected (-1 if not selected or fully selected)<br/>
311327
/// if the given word is not starting or ending selection word -1 is returned as full word selection is in place.

‎Source/HtmlRenderer/HtmlContainer.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,22 @@ public SizeF ActualSize
323323
internal set { _actualSize = value; }
324324
}
325325

326+
/// <summary>
327+
/// Get the currently selected text segment in the html.
328+
/// </summary>
329+
public string SelectedText
330+
{
331+
get { return _selectionHandler.GetSelectedText(); }
332+
}
333+
334+
/// <summary>
335+
/// Copy the currently selected html segment with style.
336+
/// </summary>
337+
public string SelectedHtml
338+
{
339+
get { return _selectionHandler.GetSelectedHtml(); }
340+
}
341+
326342
/// <summary>
327343
/// the root css box of the parsed html
328344
/// </summary>

‎Source/HtmlRenderer/HtmlLabel.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,24 @@ public override string Text
283283
}
284284
}
285285

286+
/// <summary>
287+
/// Get the currently selected text segment in the html.
288+
/// </summary>
289+
[Browsable(false)]
290+
public string SelectedText
291+
{
292+
get { return _htmlContainer.SelectedText; }
293+
}
294+
295+
/// <summary>
296+
/// Copy the currently selected html segment with style.
297+
/// </summary>
298+
[Browsable(false)]
299+
public string SelectedHtml
300+
{
301+
get { return _htmlContainer.SelectedHtml; }
302+
}
303+
286304
/// <summary>
287305
/// Get html from the current DOM tree with inline style.
288306
/// </summary>

‎Source/HtmlRenderer/HtmlPanel.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ public override string Text
229229
}
230230
}
231231

232+
/// <summary>
233+
/// Get the currently selected text segment in the html.
234+
/// </summary>
235+
[Browsable(false)]
236+
public string SelectedText
237+
{
238+
get { return _htmlContainer.SelectedText; }
239+
}
240+
241+
/// <summary>
242+
/// Copy the currently selected html segment with style.
243+
/// </summary>
244+
[Browsable(false)]
245+
public string SelectedHtml
246+
{
247+
get { return _htmlContainer.SelectedHtml; }
248+
}
249+
232250
/// <summary>
233251
/// Get html from the current DOM tree with inline style.
234252
/// </summary>

0 commit comments

Comments
 (0)