Skip to content

Commit

Permalink
Desktop: Toggle Editor rather than setting split mode on search (laur…
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebJohn committed Aug 1, 2020
1 parent baea44c commit bab29cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
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

0 comments on commit bab29cd

Please sign in to comment.