[DE] Make new search: edit shortcut method

This commit is contained in:
JuliaSvinareva 2022-03-03 21:55:36 +03:00
parent 2bfe6b2d2c
commit f91f696cd6
5 changed files with 80 additions and 25 deletions

View file

@ -116,12 +116,17 @@ define([
return this; return this;
}, },
show: function() { show: function(text) {
var top = $('#app-title').height() + $('#toolbar').height() + 2, var top = $('#app-title').height() + $('#toolbar').height() + 2,
left = Common.Utils.innerWidth() - ($('#right-menu').is(':visible') ? $('#right-menu').width() : 0) - this.options.width - 32; left = Common.Utils.innerWidth() - ($('#right-menu').is(':visible') ? $('#right-menu').width() : 0) - this.options.width - 32;
Common.UI.Window.prototype.show.call(this, left, top); Common.UI.Window.prototype.show.call(this, left, top);
this.inputSearch.val(''); if (text) {
this.inputSearch.val(text);
} else {
this.inputSearch.val('');
}
this.focus(); this.focus();
}, },
@ -133,6 +138,10 @@ define([
}, 10); }, 10);
}, },
setText: function (text) {
this.inputSearch.val(text);
},
getSettings: function() { getSettings: function() {
return { return {

View file

@ -210,11 +210,12 @@ define([
this.fireEvent('hide', this ); this.fireEvent('hide', this );
}, },
focus: function() { focus: function(type) {
var me = this; var me = this,
el = type === 'replace' ? me.inputReplace.$el : me.inputText.$el;
setTimeout(function(){ setTimeout(function(){
me.inputText.$el.find('input').focus(); el.find('input').focus();
me.inputText.$el.find('input').select(); el.find('input').select();
}, 10); }, 10);
}, },
@ -243,7 +244,7 @@ define([
textreplace : this.inputReplace.getValue(), textreplace : this.inputReplace.getValue(),
matchcase : this.chCaseSensitive.checked, matchcase : this.chCaseSensitive.checked,
useregexp : this.chUseRegExp.checked, useregexp : this.chUseRegExp.checked,
matchword : this.chMatchWord.checked, matchword : this.chMatchWord && this.chMatchWord.checked,
//highlight : this.miHighlight.checked //highlight : this.miHighlight.checked
}; };
this.fireEvent('search:'+action, [this, opts, true]); this.fireEvent('search:'+action, [this, opts, true]);

View file

@ -80,7 +80,8 @@ define([
}, },
'LeftMenu': { 'LeftMenu': {
'comments:show': _.bind(this.commentsShowHide, this, 'show'), 'comments:show': _.bind(this.commentsShowHide, this, 'show'),
'comments:hide': _.bind(this.commentsShowHide, this, 'hide') 'comments:hide': _.bind(this.commentsShowHide, this, 'hide'),
'search:aftershow': _.bind(this.onShowAfterSearch, this)
}, },
'FileMenu': { 'FileMenu': {
'menu:hide': _.bind(this.menuFilesShowHide, this, 'hide'), 'menu:hide': _.bind(this.menuFilesShowHide, this, 'hide'),
@ -798,10 +799,29 @@ define([
switch (s) { switch (s) {
case 'replace': case 'replace':
case 'search': case 'search':
Common.UI.Menu.Manager.hideAll();
this.showSearchDlg(true,s);
this.leftMenu.btnSearch.toggle(true,true);
this.leftMenu.btnAbout.toggle(false); this.leftMenu.btnAbout.toggle(false);
var selectedText = this.api.asc_GetSelectedText();
if (this.isSearchPanelVisible()) {
selectedText && this.leftMenu.panelSearch.setFindText(selectedText);
this.leftMenu.panelSearch.focus(s);
return false;
} else if (this.getApplication().getController('Viewport').isSearchBarVisible()) {
if (s === 'replace') {
this.getApplication().getController('Viewport').header.btnSearch.toggle(false);
this.onShowHideSearch(true, this.getApplication().getController('Viewport').searchBar.inputSearch.val());
} else {
selectedText && this.getApplication().getController('Viewport').searchBar.setText(selectedText);
this.getApplication().getController('Viewport').searchBar.focus();
return false;
}
} else if (s === 'search') {
Common.NotificationCenter.trigger('search:show');
return false;
} else {
this.onShowHideSearch(true, selectedText);
}
this.leftMenu.btnSearchBar.toggle(true,true);
this.leftMenu.panelSearch.focus(s);
// this.leftMenu.menuFile.hide(); // this.leftMenu.menuFile.hide();
return false; return false;
case 'save': case 'save':
@ -921,24 +941,37 @@ define([
} }
}, },
onShowHideSearch: function (state, findText, action) { onShowHideSearch: function (state, findText) {
if (state) { if (state) {
Common.UI.Menu.Manager.hideAll(); Common.UI.Menu.Manager.hideAll();
var mode = this.mode.isEdit && !this.viewmode ? (action || undefined) : 'no-replace';
findText && this.leftMenu.panelSearch.setFindText(findText);
this.leftMenu.panelSearch.setSearchMode(mode);
this.leftMenu.showMenu('advancedsearch'); this.leftMenu.showMenu('advancedsearch');
this.onShowAfterSearch(findText);
} else { } else {
this.leftMenu.btnSearchBar.toggle(false, true); this.leftMenu.btnSearchBar.toggle(false, true);
this.leftMenu.onBtnMenuClick(this.leftMenu.btnSearchBar); this.leftMenu.onBtnMenuClick(this.leftMenu.btnSearchBar);
} }
}, },
onShowAfterSearch: function (findText) {
var text = findText || this.api.asc_GetSelectedText();
if (text) {
this.leftMenu.panelSearch.setFindText(text);
} else if (text !== undefined) {
this.leftMenu.panelSearch.setFindText('');
}
this.leftMenu.panelSearch.focus();
},
onMenuSearchBar: function(obj, show) { onMenuSearchBar: function(obj, show) {
if (show) { if (show) {
var mode = this.mode.isEdit && !this.viewmode ? undefined : 'no-replace'; var mode = this.mode.isEdit && !this.viewmode ? undefined : 'no-replace';
this.leftMenu.panelSearch.setSearchMode(mode); this.leftMenu.panelSearch.setSearchMode(mode);
} }
this.leftMenu._state.isSearchOpen = show;
},
isSearchPanelVisible: function () {
return this.leftMenu._state.isSearchOpen;
}, },
isCommentsVisible: function() { isCommentsVisible: function() {

View file

@ -164,6 +164,7 @@ define([
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
Common.NotificationCenter.on('uitheme:changed', this.onThemeChanged.bind(this)); Common.NotificationCenter.on('uitheme:changed', this.onThemeChanged.bind(this));
Common.NotificationCenter.on('contenttheme:dark', this.onContentThemeChangedToDark.bind(this)); Common.NotificationCenter.on('contenttheme:dark', this.onContentThemeChangedToDark.bind(this));
Common.NotificationCenter.on('search:show', _.bind(this.onSearchShow, this));
}, },
onAppShowed: function (config) { onAppShowed: function (config) {
@ -339,7 +340,7 @@ define([
me.header.menuItemsDarkMode.$el.prev('.divider').hide(); me.header.menuItemsDarkMode.$el.prev('.divider').hide();
} }
} }
me.header.btnSearch.on('click', me.onSearchClick.bind(this)); me.header.btnSearch.on('toggle', me.onSearchToggle.bind(this));
}, },
onLayoutChanged: function(area) { onLayoutChanged: function(area) {
@ -462,22 +463,32 @@ define([
this.header && this.header.lockHeaderBtns( 'rename-user', disable); this.header && this.header.lockHeaderBtns( 'rename-user', disable);
}, },
onSearchClick: function () { onSearchShow: function () {
this.header.btnSearch && this.header.btnSearch.toggle(true);
},
onSearchToggle: function () {
var leftMenu = this.getApplication().getController('LeftMenu');
if (leftMenu.isSearchPanelVisible()) {
this.header.btnSearch.toggle(false, true);
leftMenu.getView('LeftMenu').panelSearch.focus();
return;
}
if (!this.searchBar) { if (!this.searchBar) {
this.searchBar = new Common.UI.SearchBar({}); this.searchBar = new Common.UI.SearchBar({});
this.searchBar.on('hide', _.bind(function () {
this.header.btnSearch.toggle(false, true);
}, this));
} }
if (this.header.btnSearch.pressed) { if (this.header.btnSearch.pressed) {
if (this.searchBar.isVisible()) { this.searchBar.show(this.api.asc_GetSelectedText());
this.searchBar.focus();
} else {
this.searchBar.show();
}
} else { } else {
this.searchBar.hide(); this.searchBar.hide();
} }
this.searchBar.on('hide', _.bind(function () { },
this.header.btnSearch.toggle(false);
}, this)); isSearchBarVisible: function () {
return this.searchBar && this.searchBar.isVisible();
}, },
textFitPage: 'Fit to Page', textFitPage: 'Fit to Page',

View file

@ -271,6 +271,7 @@ define([
if (this.panelSearch) { if (this.panelSearch) {
if (this.btnSearchBar.pressed) { if (this.btnSearchBar.pressed) {
this.panelSearch.show(); this.panelSearch.show();
this.fireEvent('search:aftershow', this);
} else { } else {
this.panelSearch.hide(); this.panelSearch.hide();
} }