void BookmarkView::onTreeSelect( wxTreeEvent& event ) { if (skipEvents()) { return; } wxTreeItemId itm = event.GetItem(); TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(itm)); if (!tvi) { if (itm == bookmarkBranch) { bookmarkBranchSelection(); } else if (itm == activeBranch) { activeBranchSelection(); } else if (itm == recentBranch) { recentBranchSelection(); } else if (itm == rangeBranch) { rangeBranchSelection(); } else { hideProps(); this->Layout(); } return; } if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) { activeSelection(tvi->demod); if (tvi->demod->isActive()) { wxGetApp().getDemodMgr().setActiveDemodulator(nullptr, true); wxGetApp().getDemodMgr().setActiveDemodulator(tvi->demod, false); tvi->demod->setTracking(true); } } else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) { recentSelection(tvi->bookmarkEnt); } else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) { bookmarkSelection(tvi->bookmarkEnt); } else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP) { groupSelection(tvi->groupName); } else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE) { rangeSelection(tvi->rangeEnt); } else { hideProps(); this->Layout(); } }
VisibleSelection visibleSelectionForClosestActualWordStart(const VisibleSelection& selection) { // VisibleSelection validation has a special case when the caret is at the end of a paragraph where // it selects the paragraph marker. As well, if the position is at the end of a word, it will select // only the space between words. We want to select an actual word so we move the selection to // the start of the leftmost word if the character after the selection point is whitespace. if (selection.selectionType() != VisibleSelection::RangeSelection) { int leftDistance = 0; int rightDistance = 0; VisibleSelection leftSelection(previousWordPosition(selection.start())); bool leftSelectionIsOnWord = !isWhitespace(leftSelection.visibleStart().characterAfter()) && leftSelection.start().containerNode() == selection.start().containerNode(); if (leftSelectionIsOnWord) { VisibleSelection rangeSelection(endOfWord(leftSelection.start()), selection.visibleStart()); leftDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get()); } VisibleSelection rightSelection = previousWordPosition(nextWordPosition(selection.start())); bool rightSelectionIsOnWord = !isWhitespace(rightSelection.visibleStart().characterAfter()) && rightSelection.start().containerNode() == selection.start().containerNode(); if (rightSelectionIsOnWord) { VisibleSelection rangeSelection = VisibleSelection(rightSelection.visibleStart(), selection.visibleStart()); rightDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get()); } // Make sure we found an actual word. If not, return the original selection. if (!leftSelectionIsOnWord && !rightSelectionIsOnWord) return selection; if (!rightSelectionIsOnWord || (leftSelectionIsOnWord && leftDistance <= rightDistance)) { // Left is closer or right is invalid. return leftSelection; } // Right is closer or equal, or left was invalid. return rightSelection; } // No adjustment required. return selection; }