find/replace in editors; #178 #47

This commit is contained in:
Vadim Lopatin 2017-09-04 18:07:38 +03:00
parent cfb0e63145
commit 3ea66645b8
2 changed files with 33 additions and 10 deletions

View File

@ -3130,7 +3130,7 @@ class EditBox : EditWidgetBase {
/// create find panel
protected void createFindPanel(bool selectionOnly, bool replaceMode) {
if (_findPanel) {
closeFindPanel();
closeFindPanel(false);
}
dstring txt = selectionText(true);
_findPanel = new FindPanel(this, selectionOnly, replaceMode, txt);
@ -3142,12 +3142,17 @@ class EditBox : EditWidgetBase {
}
/// close find panel
protected void closeFindPanel() {
protected void closeFindPanel(bool hideOnly = true) {
if (_findPanel) {
removeChild(_findPanel);
destroy(_findPanel);
_findPanel = null;
requestLayout();
setFocus();
if (hideOnly) {
_findPanel.visibility = Visibility.Gone;
} else {
removeChild(_findPanel);
destroy(_findPanel);
_findPanel = null;
requestLayout();
}
}
}
@ -3323,12 +3328,14 @@ class FindPanel : HorizontalLayout {
_cbCaseSensitive = childById!ImageCheckButton("cbCaseSensitive");
_cbWholeWords = childById!ImageCheckButton("cbWholeWords");
_cbSelection = childById!CheckBox("cbSelection");
_cbCaseSensitive.checkChange = &onCaseSensitiveCheckChange;
if (!replace)
childById("replace").visibility = Visibility.Gone;
//_edFind = new EditLine("edFind"
dstring currentText = _edFind.text;
Log.d("currentText=", currentText);
setDirection(false);
updateHighlight();
}
void activate() {
_edFind.setFocus();
@ -3389,13 +3396,29 @@ class FindPanel : HorizontalLayout {
dstring currentText = _edFind.text;
Log.d("findNext text=", currentText, " back=", back);
_editor.setTextToHighlight(currentText, _cbCaseSensitive.checked);
TextPosition pos = _editor.caretPos;
bool res = _editor.findNextPattern(pos, currentText, _cbCaseSensitive.checked, back ? -1 : 1);
if (res) {
_editor.setCaretPos(pos.line, pos.pos, true);
}
}
void updateHighlight() {
dstring currentText = _edFind.text;
Log.d("onFindTextChange.currentText=", currentText);
_editor.setTextToHighlight(currentText, _cbCaseSensitive.checked);
}
void onFindTextChange(EditableContent source) {
Log.d("onFindTextChange");
dstring currentText = _edFind.text;
Log.d("onFindTextChange.currentText=", currentText);
updateHighlight();
}
bool onCaseSensitiveCheckChange(Widget source, bool checkValue) {
updateHighlight();
return true;
}
bool onFindEditorAction(const Action action) {
Log.d("onFindEditorAction ", action);
if (action.id == EditorActions.InsertNewLine) {

View File

@ -12,8 +12,8 @@
<color id="editor_matching_bracket_highlight" value="#60FFE0B0"/>
<color id="editor_selection_focused" value="#B060A0FF"/>
<color id="editor_selection_normal" value="#D060A0FF"/>
<color id="editor_search_highlight_current" value="#808080FF"/>
<color id="editor_search_highlight_other" value="#C08080FF"/>
<color id="editor_search_highlight_current" value="#60FFC040"/>
<color id="editor_search_highlight_other" value="#90F0D080"/>
<color id="editor_left_pane_background" value="#F4F4F4"/>
<color id="editor_left_pane_background2" value="#FFFFFF"/>
<color id="editor_left_pane_background3" value="#F0F0F0"/>