| 798 | } |
| 799 | |
| 800 | void ContextBrowserPlugin::updateForView(View* view) |
| 801 | { |
| 802 | bool allowHighlight = true; |
| 803 | if (view->selection()) { |
| 804 | // If something is selected, we unhighlight everything, so that we don't conflict with the |
| 805 | // kate plugin that highlights occurrences of the selected string, and also to reduce the |
| 806 | // overall amount of concurrent highlighting. |
| 807 | allowHighlight = false; |
| 808 | } |
| 809 | |
| 810 | if (m_highlightedRanges[view].keep) { |
| 811 | m_highlightedRanges[view].keep = false; |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | // Clear all highlighting |
| 816 | m_highlightedRanges.clear(); |
| 817 | |
| 818 | // Re-highlight |
| 819 | ViewHighlights& highlights = m_highlightedRanges[view]; |
| 820 | |
| 821 | QUrl url = view->document()->url(); |
| 822 | IDocument* activeDoc = core()->documentController()->activeDocument(); |
| 823 | |
| 824 | bool mouseHighlight = (url == m_mouseHoverDocument) && (m_mouseHoverCursor.isValid()); |
| 825 | bool shouldUpdateBrowser = |
| 826 | (mouseHighlight || |
| 827 | (view == ICore::self()->documentController()->activeTextDocumentView() && activeDoc && |
| 828 | activeDoc->textDocument() == view->document())); |
| 829 | |
| 830 | KTextEditor::Cursor highlightPosition; |
| 831 | if (mouseHighlight) |
| 832 | highlightPosition = m_mouseHoverCursor; |
| 833 | else |
| 834 | highlightPosition = KTextEditor::Cursor(view->cursorPosition()); |
| 835 | |
| 836 | ///Pick a language |
| 837 | ILanguageSupport* const language = ICore::self()->languageController()->languagesForUrl(url).value(0); |
| 838 | if (!language) { |
| 839 | qCDebug(PLUGIN_CONTEXTBROWSER) << "found no language for document" << url; |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | ///Check whether there is a special language object to highlight (for example a macro) |
| 844 | |
| 845 | KTextEditor::Range specialRange = language->specialLanguageObjectRange(url, highlightPosition); |
| 846 | ContextBrowserView* updateBrowserView = shouldUpdateBrowser ? browserViewForWidget(view) : nullptr; |
| 847 | |
| 848 | if (specialRange.isValid()) { |
| 849 | // Highlight a special language object |
| 850 | if (allowHighlight) { |
| 851 | highlights.highlights << |
| 852 | PersistentMovingRange::Ptr(new PersistentMovingRange(specialRange, IndexedString(url))); |
| 853 | highlights.highlights.back()->setAttribute(highlightedSpecialObjectAttribute()); |
| 854 | highlights.highlights.back()->setZDepth(highlightingZDepth); |
| 855 | } |
| 856 | if (updateBrowserView) |
| 857 | updateBrowserView->setSpecialNavigationWidget(language->specialLanguageObjectNavigationWidget(url, |
nothing calls this directly
no test coverage detected