Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Toggle Editor rather than setting split mode on search #3561

Merged
merged 3 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions ElectronClient/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,6 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {

useEffect(() => {
if (props.searchMarkers !== previousSearchMarkers || renderedBody !== previousRenderedBody) {
// Force both viewers to be visible during search
// This view should only change when the search terms change, this means the user
// is always presented with the currently highlighted text, but can revert
// to the viewer if they only want to scroll through matches
if (!props.visiblePanes.includes('editor') && props.searchMarkers !== previousSearchMarkers) {
props.dispatch({
type: 'NOTE_VISIBLE_PANES_SET',
panes: ['editor', 'viewer'],
});
}
// SEARCHHACK
// TODO: remove this options hack when aceeditor is removed
// Currently the webviewRef will send out an ipcMessage to set the results count
Expand All @@ -421,9 +411,17 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
webviewRef.current.wrappedInstance.send('setMarkers', props.searchMarkers.keywords, options);
// SEARCHHACK
if (editorRef.current) {

const matches = editorRef.current.setMarkers(props.searchMarkers.keywords, props.searchMarkers.options);
props.setLocalSearchResultCount(matches);

// SEARCHHACK
// TODO: when aceeditor is removed then this check will be performed in the NoteSearchbar
// End the if statement can be removed in favor of simply returning matches
if (props.visiblePanes.includes('editor')) {
props.setLocalSearchResultCount(matches);
} else {
props.setLocalSearchResultCount(-1);
}
// end SEARCHHACK
}
}
}, [props.searchMarkers, props.setLocalSearchResultCount, renderedBody]);
Expand Down
22 changes: 19 additions & 3 deletions ElectronClient/gui/NoteSearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ class NoteSearchBarComponent extends React.Component {
</div>
) : null;

// Currently searching in the viewer does not support jumping between matches
// So we explicitly disable those commands when only the viewer is open (this is
// currently signaled by results count being set to -1, but once Ace editor is removed
// we can observe the visible panes directly).
// SEARCHHACK
// TODO: remove the props.resultCount check here and replace it by checking visible panes directly
const allowScrolling = this.props.resultCount !== -1;
// end SEARCHHACK

const viewerWarning = (
<div style={textStyle}>
{'Jumping between matches is not available in the viewer, please toggle the editor'}
</div>
);

return (
<div style={this.props.style}>
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
Expand All @@ -161,9 +176,10 @@ class NoteSearchBarComponent extends React.Component {
type="text"
style={{ width: 200, marginRight: 5, backgroundColor: this.backgroundColor, color: theme.color }}
/>
{nextButton}
{previousButton}
{matchesFoundString}
{allowScrolling ? nextButton : null}
{allowScrolling ? previousButton : null}
{allowScrolling ? matchesFoundString : null}
{!allowScrolling ? viewerWarning : null}
</div>
</div>
);
Expand Down