From 9275c7a40cebb18e4c4593c9dd8a06ce655e2757 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 25 Jun 2015 08:22:24 +0100 Subject: Set the parent tab when creating tabs. If the tab is subsequently deleted, then we return to the original tab (as opposed to the one on its right). --- background_scripts/main.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 28959d35..4cb78441 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -204,6 +204,7 @@ openUrlInNewTab = (request, callback) -> index: tab.index + 1 selected: true windowId: tab.windowId + openerTabId: tab.id # FIXME(smblott). openUrlInNewTab is being called in two different ways with different arguments. We # should refactor it such that this check on callback isn't necessary. callback = (->) unless typeof callback == "function" -- cgit v1.2.3 From d9e8da958d55de5c8880b336255cf8987986be93 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 25 Jun 2015 12:16:51 +0100 Subject: Make global marks consistent with other tab creation operations. This makes global marks use the same code for opening new tabs as other operations. Thus, the new tab appears in the same position as it would if it were created, for example, via the vomnibar. To do this properly, we move the three tab-creating functions into an object which can be (and is) exported (TabOperations). Also fixes these three operations such that they all take the same arguments; that is (request, callback). Not all of these callbacks are being used. But we should be consistent. --- background_scripts/main.coffee | 57 ++++++++++++++++++++--------------------- background_scripts/marks.coffee | 2 +- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 4cb78441..40d570ee 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -187,31 +187,28 @@ getCompletionKeysRequest = (request, keysToCheck = "") -> completionKeys: generateCompletionKeys(keysToCheck) validFirstKeys: validFirstKeys -# -# Opens the url in the current tab. -# -openUrlInCurrentTab = (request) -> - chrome.tabs.getSelected(null, - (tab) -> chrome.tabs.update(tab.id, { url: Utils.convertToUrl(request.url) })) +TabOperations = + # Opens the url in the current tab. + openUrlInCurrentTab: (request, callback = (->)) -> + chrome.tabs.getSelected null, (tab) -> + callback = (->) unless typeof callback == "function" + chrome.tabs.update tab.id, { url: Utils.convertToUrl(request.url) }, callback -# -# Opens request.url in new tab and switches to it if request.selected is true. -# -openUrlInNewTab = (request, callback) -> - chrome.tabs.getSelected null, (tab) -> - tabConfig = - url: Utils.convertToUrl request.url - index: tab.index + 1 - selected: true - windowId: tab.windowId + # Opens request.url in new tab and switches to it if request.selected is true. + openUrlInNewTab: (request, callback = (->)) -> + chrome.tabs.getSelected null, (tab) -> + tabConfig = + url: Utils.convertToUrl request.url + index: tab.index + 1 + selected: true + windowId: tab.windowId openerTabId: tab.id - # FIXME(smblott). openUrlInNewTab is being called in two different ways with different arguments. We - # should refactor it such that this check on callback isn't necessary. - callback = (->) unless typeof callback == "function" - chrome.tabs.create tabConfig, callback + callback = (->) unless typeof callback == "function" + chrome.tabs.create tabConfig, callback -openUrlInIncognito = (request) -> - chrome.windows.create({ url: Utils.convertToUrl(request.url), incognito: true}) + openUrlInIncognito: (request, callback = (->)) -> + callback = (->) unless typeof callback == "function" + chrome.windows.create {url: Utils.convertToUrl(request.url), incognito: true}, callback # # Copies or pastes some data (request.data) to/from the clipboard. @@ -257,7 +254,7 @@ BackgroundCommands = if url == "pages/blank.html" # "pages/blank.html" does not work in incognito mode, so fall back to "chrome://newtab" instead. url = if tab.incognito then "chrome://newtab" else chrome.runtime.getURL url - openUrlInNewTab { url }, callback + TabOperations.openUrlInNewTab { url }, callback duplicateTab: (callback) -> chrome.tabs.getSelected(null, (tab) -> chrome.tabs.duplicate(tab.id) @@ -297,8 +294,8 @@ BackgroundCommands = scrollX: tabQueueEntry.scrollX, scrollY: tabQueueEntry.scrollY) callback())) - openCopiedUrlInCurrentTab: (request) -> openUrlInCurrentTab({ url: Clipboard.paste() }) - openCopiedUrlInNewTab: (request) -> openUrlInNewTab({ url: Clipboard.paste() }) + openCopiedUrlInCurrentTab: (request) -> TabOperations.openUrlInCurrentTab({ url: Clipboard.paste() }) + openCopiedUrlInNewTab: (request) -> TabOperations.openUrlInNewTab({ url: Clipboard.paste() }) togglePinTab: (request) -> chrome.tabs.getSelected(null, (tab) -> chrome.tabs.update(tab.id, { pinned: !tab.pinned })) @@ -653,9 +650,9 @@ portHandlers = sendRequestHandlers = getCompletionKeys: getCompletionKeysRequest getCurrentTabUrl: getCurrentTabUrl - openUrlInNewTab: openUrlInNewTab - openUrlInIncognito: openUrlInIncognito - openUrlInCurrentTab: openUrlInCurrentTab + openUrlInNewTab: TabOperations.openUrlInNewTab + openUrlInIncognito: TabOperations.openUrlInIncognito + openUrlInCurrentTab: TabOperations.openUrlInCurrentTab openOptionsPageInNewTab: openOptionsPageInNewTab registerFrame: registerFrame unregisterFrame: unregisterFrame @@ -726,7 +723,7 @@ showUpgradeMessage = -> Settings.set "previousVersion", currentVersion chrome.notifications.onClicked.addListener (id) -> if id == notificationId - openUrlInNewTab url: "https://github.com/philc/vimium#release-notes" + TabOperations.openUrlInNewTab url: "https://github.com/philc/vimium#release-notes" else # We need to wait for the user to accept the "notifications" permission. chrome.permissions.onAdded.addListener showUpgradeMessage @@ -741,3 +738,5 @@ chrome.windows.getAll { populate: true }, (windows) -> chrome.tabs.sendMessage(tab.id, { name: "getScrollPosition" }, createScrollPositionHandler()) showUpgradeMessage() + +root.TabOperations = TabOperations diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee index 6e5f08ba..70ec1c17 100644 --- a/background_scripts/marks.coffee +++ b/background_scripts/marks.coffee @@ -82,7 +82,7 @@ Marks = @gotoPositionInTab extend markInfo, tabId: tab.id else # There is no existing matching tab, we'll have to create one. - chrome.tabs.create { url: @getBaseUrl markInfo.url }, (tab) => + TabOperations.openUrlInNewTab { url: @getBaseUrl markInfo.url }, (tab) => # Note. tabLoadedHandlers is defined in "main.coffee". The handler below will be called when the tab # is loaded, its DOM is ready and it registers with the background page. tabLoadedHandlers[tab.id] = => @gotoPositionInTab extend markInfo, tabId: tab.id -- cgit v1.2.3 From 6637d09d4043154bdf37a063137f4074a1dc3239 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 26 Jun 2015 11:00:58 +0100 Subject: Fix oversight from #1693. (We need to use "this" inside this function.) --- content_scripts/mode_find.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index d7c628be..9b47cfbd 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -101,7 +101,7 @@ class FindMode extends Mode # character. here we grep for the relevant escape sequences. @query.isRegex = Settings.get 'regexFindMode' hasNoIgnoreCaseFlag = false - @query.parsedQuery = @query.rawQuery.replace /(\\{1,2})([rRI]?)/g, (match, slashes, flag) -> + @query.parsedQuery = @query.rawQuery.replace /(\\{1,2})([rRI]?)/g, (match, slashes, flag) => return match if flag == "" or slashes.length != 1 switch (flag) when "r" -- cgit v1.2.3