Skip to content

Commit b1731f5

Browse files
author
Arthur Teplitzki
committed
add clear selection
1 parent db24dc5 commit b1731f5

7 files changed

Lines changed: 77 additions & 22 deletions

File tree

‎Source/HtmlRenderer.WPF/HtmlContainer.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ public string SelectedHtml
248248
get { return _htmlContainerInt.SelectedHtml; }
249249
}
250250

251+
/// <summary>
252+
/// Clear the current selection.
253+
/// </summary>
254+
public void ClearSelection()
255+
{
256+
HtmlContainerInt.ClearSelection();
257+
}
258+
251259
/// <summary>
252260
/// Init with optional document and stylesheet.
253261
/// </summary>

‎Source/HtmlRenderer.WPF/HtmlControl.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ public virtual string GetHtml()
250250
return _htmlContainer != null ? _htmlContainer.GetElementRectangle(elementId) : null;
251251
}
252252

253+
/// <summary>
254+
/// Clear the current selection.
255+
/// </summary>
256+
public void ClearSelection()
257+
{
258+
if (_htmlContainer != null)
259+
_htmlContainer.ClearSelection();
260+
}
261+
253262

254263
#region Private methods
255264

‎Source/HtmlRenderer.WinForms/HtmlContainer.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ public string SelectedHtml
287287
get { return _htmlContainerInt.SelectedHtml; }
288288
}
289289

290+
/// <summary>
291+
/// Clear the current selection.
292+
/// </summary>
293+
public void ClearSelection()
294+
{
295+
HtmlContainerInt.ClearSelection();
296+
}
297+
290298
/// <summary>
291299
/// Init with optional document and stylesheet.
292300
/// </summary>

‎Source/HtmlRenderer.WinForms/HtmlLabel.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ public virtual string GetHtml()
435435
return _htmlContainer != null ? _htmlContainer.GetElementRectangle(elementId) : null;
436436
}
437437

438+
/// <summary>
439+
/// Clear the current selection.
440+
/// </summary>
441+
public void ClearSelection()
442+
{
443+
if (_htmlContainer != null)
444+
_htmlContainer.ClearSelection();
445+
}
446+
438447

439448
#region Private methods
440449

‎Source/HtmlRenderer.WinForms/HtmlPanel.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ public virtual void ScrollToElement(string elementId)
402402
}
403403
}
404404

405+
/// <summary>
406+
/// Clear the current selection.
407+
/// </summary>
408+
public void ClearSelection()
409+
{
410+
if (_htmlContainer != null)
411+
_htmlContainer.ClearSelection();
412+
}
413+
405414

406415
#region Private methods
407416

‎Source/HtmlRenderer/Core/Handlers/SelectionHandler.cs‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,26 @@ public double GetSelectedEndOffset(CssRect word)
378378
return word == (_backwardSelection ? _selectionStart : _selectionEnd) ? (_backwardSelection ? _selectionStartOffset : _selectionEndOffset) : -1;
379379
}
380380

381+
/// <summary>
382+
/// Clear the current selection.
383+
/// </summary>
384+
public void ClearSelection()
385+
{
386+
// clear drag and drop
387+
_dragDropData = null;
388+
389+
ClearSelection(_root);
390+
391+
_selectionStartOffset = -1;
392+
_selectionStartIndex = -1;
393+
_selectionEndOffset = -1;
394+
_selectionEndIndex = -1;
395+
396+
_selectionStartPoint = RPoint.Empty;
397+
_selectionStart = null;
398+
_selectionEnd = null;
399+
}
400+
381401
/// <summary>
382402
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
383403
/// </summary>
@@ -461,26 +481,6 @@ private void HandleSelection(RControl control, RPoint loc, bool allowPartialSele
461481
}
462482
}
463483

464-
/// <summary>
465-
/// Clear the current selection.
466-
/// </summary>
467-
private void ClearSelection()
468-
{
469-
// clear drag and drop
470-
_dragDropData = null;
471-
472-
ClearSelection(_root);
473-
474-
_selectionStartOffset = -1;
475-
_selectionStartIndex = -1;
476-
_selectionEndOffset = -1;
477-
_selectionEndIndex = -1;
478-
479-
_selectionStartPoint = RPoint.Empty;
480-
_selectionStart = null;
481-
_selectionEnd = null;
482-
}
483-
484484
/// <summary>
485485
/// Clear the selection from all the words in the css box recursively.
486486
/// </summary>

‎Source/HtmlRenderer/Core/HtmlContainerInt.cs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,17 +435,29 @@ public void Clear()
435435
{
436436
_root.Dispose();
437437
_root = null;
438-
438+
439439
if (_selectionHandler != null)
440440
_selectionHandler.Dispose();
441441
_selectionHandler = null;
442-
442+
443443
if (_imageDownloader != null)
444444
_imageDownloader.Dispose();
445445
_imageDownloader = null;
446446
}
447447
}
448448

449+
/// <summary>
450+
/// Clear the current selection.
451+
/// </summary>
452+
public void ClearSelection()
453+
{
454+
if (_selectionHandler != null)
455+
{
456+
_selectionHandler.ClearSelection();
457+
RequestRefresh(false);
458+
}
459+
}
460+
449461
/// <summary>
450462
/// Get html from the current DOM tree with style if requested.
451463
/// </summary>

0 commit comments

Comments
 (0)