Skip to content

Commit 52c0818

Browse files
committed
fix #256 - crash on FindInFiles when there is no opened editor
1 parent 5c72e87 commit 52c0818

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

src/dlangide/ui/frame.d

+4-1
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,11 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
11081108
_logPanel.getTabs.selectTab("search");
11091109
if(searchPanel !is null) {
11101110
searchPanel.focus();
1111-
dstring selectedText = currentEditor.getSelectedText();
1111+
dstring selectedText;
1112+
if (currentEditor)
1113+
selectedText = currentEditor.getSelectedText();
11121114
searchPanel.setSearchText(selectedText);
1115+
searchPanel.checkSearchMode();
11131116
}
11141117
return true;
11151118
case IDEActions.FileNewWorkspace:

src/dlangide/ui/searchPanel.d

+43-9
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class SearchWidget : TabWidget {
152152
SearchLogWidget _resultLog;
153153
int _resultLogMatchIndex;
154154
ComboBox _searchScope;
155+
ImageCheckButton _cbCaseSensitive;
156+
ImageCheckButton _cbWholeWords;
155157

156158
protected IDEFrame _frame;
157159
protected SearchMatchList[] _matchedList;
@@ -206,6 +208,18 @@ class SearchWidget : TabWidget {
206208
_searchScope = new ComboBox("searchScope", ["File"d, "Project"d, "Dependencies"d, "Everywhere"d]);
207209
_searchScope.selectedItemIndex = 0;
208210
_layout.addChild(_searchScope);
211+
212+
_cbCaseSensitive = new ImageCheckButton("cbCaseSensitive", "find_case_sensitive");
213+
_cbCaseSensitive.tooltipText = "EDIT_FIND_CASE_SENSITIVE";
214+
_cbCaseSensitive.styleId = "TOOLBAR_BUTTON";
215+
_cbCaseSensitive.checked = true;
216+
_layout.addChild(_cbCaseSensitive);
217+
218+
_cbWholeWords = new ImageCheckButton("cbWholeWords", "find_whole_words");
219+
_cbWholeWords.tooltipText = "EDIT_FIND_WHOLE_WORDS";
220+
_cbWholeWords.styleId = "TOOLBAR_BUTTON";
221+
_layout.addChild(_cbWholeWords);
222+
209223
addChild(_layout);
210224

211225
_resultLog = new SearchLogWidget("SearchLogWidget");
@@ -250,9 +264,11 @@ class SearchWidget : TabWidget {
250264

251265
switch (_searchScope.text) {
252266
case "File":
253-
SearchMatchList match = findMatches(_frame.currentEditor.filename, source);
254-
if(match.matches.length > 0)
255-
_matchedList ~= match;
267+
if (_frame.currentEditor) {
268+
SearchMatchList match = findMatches(_frame.currentEditor.filename, source);
269+
if(match.matches.length > 0)
270+
_matchedList ~= match;
271+
}
256272
break;
257273
case "Project":
258274
foreach(Project project; _frame._wsPanel.workspace.projects) {
@@ -302,23 +318,41 @@ class SearchWidget : TabWidget {
302318
}
303319
super.onDraw(buf);
304320
}
305-
321+
322+
void checkSearchMode() {
323+
if (!_frame.currentEditor && _searchScope.selectedItemIndex == 0)
324+
_searchScope.selectedItemIndex = 1;
325+
}
326+
327+
uint makeSearchFlags() {
328+
uint res = 0;
329+
if (_cbCaseSensitive.checked)
330+
res |= TextSearchFlag.CaseSensitive;
331+
if (_cbWholeWords.checked)
332+
res |= TextSearchFlag.WholeWords;
333+
return res;
334+
}
335+
306336
//Find the match/matchList that corrosponds to the line in _resultLog
307337
bool onMatchClick(int line) {
308338
line++;
309339
foreach(matchList; _matchedList){
310340
line--;
311341
if (line == 0) {
312-
_frame.openSourceFile(matchList.filename);
313-
_frame.currentEditor.setFocus();
342+
if (_frame.openSourceFile(matchList.filename)) {
343+
_frame.currentEditor.setTextToHighlight(_findText.text, makeSearchFlags);
344+
_frame.currentEditor.setFocus();
345+
}
314346
return true;
315347
}
316348
foreach(match; matchList.matches) {
317349
line--;
318350
if (line == 0) {
319-
_frame.openSourceFile(matchList.filename);
320-
_frame.currentEditor.setCaretPos(match.line, to!int(match.col));
321-
_frame.currentEditor.setFocus();
351+
if (_frame.openSourceFile(matchList.filename)) {
352+
_frame.currentEditor.setCaretPos(match.line, to!int(match.col));
353+
_frame.currentEditor.setTextToHighlight(_findText.text, makeSearchFlags);
354+
_frame.currentEditor.setFocus();
355+
}
322356
return true;
323357
}
324358
}

views/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.7.70
1+
v0.7.71

0 commit comments

Comments
 (0)