Focus the search box on Ctrl/Cmd+F shortcut

For #229
This commit is contained in:
Yuya Ochiai
2016-08-14 00:08:18 +09:00
parent 1d851fd6de
commit 647e396fad
3 changed files with 28 additions and 1 deletions

View File

@@ -75,6 +75,12 @@ var MainPage = React.createClass({
this.refs[`mattermostView${this.state.key}`].clearCacheAndReload(); this.refs[`mattermostView${this.state.key}`].clearCacheAndReload();
}); });
// activate search box in current tab
ipcRenderer.on('activate-search-box', (event) => {
let webview = document.getElementById('mattermostView' + thisObj.state.key);
webview.send('activate-search-box');
});
var focusListener = function() { var focusListener = function() {
var webview = document.getElementById('mattermostView' + thisObj.state.key); var webview = document.getElementById('mattermostView' + thisObj.state.key);
webview.focus(); webview.focus();

View File

@@ -127,3 +127,16 @@ notification.override({
ipc.sendToHost('onNotificationClick'); ipc.sendToHost('onNotificationClick');
} }
}); });
// get the last of href for the current channel in the sidebar.
function getCurrentChannelString() {
const active_channel_link = document.querySelector('.active a.sidebar-channel');
const url_elements = active_channel_link.href.split('/');
return url_elements[url_elements.length - 1];
}
ipc.on('activate-search-box', (event) => {
const search_box = document.getElementsByClassName('search-bar')[0]; // should use id
search_box.focus();
console.log(getCurrentChannelString());
});

View File

@@ -69,7 +69,15 @@ var createTemplate = function(mainWindow, config) {
role: 'paste' role: 'paste'
}, { }, {
role: 'selectall' role: 'selectall'
}, ] }, separatorItem, {
label: 'Search in Current Channel',
accelerator: 'CmdOrCtrl+F',
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send('activate-search-box');
}
}
}]
}); });
template.push({ template.push({
label: '&View', label: '&View',