<commit_before>/* defines keybindings that aren't in the menu (so they aren't defined by menu.js). For items in the menu, also handles ipc messages */

/*
There are three possible ways that keybindings can be handled.
 Shortcuts that appear in the menubar are registered in main.js, and send IPC messages to the window (which are handled by this file)
Shortcuts that don't appear in the menubar are registered in this file, using defineShortcut(). 
 - If the browser UI is focused, these are handled by Mousetrap.
  - If a BrowserView is focused, these are handled by the before-input-event listener.
  */

const menuBarVisibility = require('menuBarVisibility.js')
var searchbar = require('searchbar/searchbar.js')
var browserUI = require('browserUI.js')
var focusMode = require('focusMode.js')
var urlParser = require('util/urlParser.js')

ipc.on('zoomIn', function () {
  webviewGestures.zoomWebviewIn(tabs.getSelected())
})

ipc.on('zoomOut', function () {
  webviewGestures.zoomWebviewOut(tabs.getSelected())
})

ipc.on('zoomReset', function () {
  webviewGestures.resetWebviewZoom(tabs.getSelected())
})

ipc.on('print', function () {
  if (PDFViewer.isPDFViewer(tabs.getSelected())) {
    PDFViewer.printPDF(tabs.getSelected())
  } else if (readerView.isReader(tabs.getSelected())) {
    readerView.printArticle(tabs.getSelected())
  } else {
    //TODO figure out why webContents.print() doesn't work in Electron 4
    webviews.get(tabs.getSelected()).executeJavaScript("window.print()")
  }
})

ipc.on('findInPage', function () {
  findinpage.start()
})

ipc.on('inspectPage', function () {
  webviews.get(tabs.getSelected()).openDevTools()
})

ipc.on('showReadingList', function () {
  // open the searchbar with "!readinglist " as the input
  tabBar.enterEditMode(tabs.getSelected(), '!readinglist ')
})

ipc.on('showBookmarks', function () {
  tabBar.enterEditMode(tabs.getSelected(), '!bookmarks ')
})

ipc.on('showHistory', function () {
  tabBar.enterEditMode(tabs.getSelected(), '!history ')
})

ipc.on('duplicateTab', function (e) {
  /* new tabs can't be created in focus mode */
  if (focusMode.enabled()) {
    focusMode.warn()
    return
  }

  // can't duplicate if tabs is empty 
  if (tabs.isEmpty()) {
    return
  }

  const newIndex = tabs.getIndex(tabs.getSelected()) + 1

  const sourceTab = tabs.get(tabs.getSelected())
  // strip tab id so that a new one is generated
  const newTab = tabs.add({...sourceTab, id: undefined}, newIndex)

  browserUI.addTab(newTab, { enterEditMode: false })
})

ipc.on('addTab', function (e, data) {
  /* new tabs can't be created in focus mode */
  if (focusMode.enabled()) {
    focusMode.warn()
    return
  }

  // if opening a URL (instead of adding an empty tab), and only an empty tab is open, navigate the current tab rather than creating another one
  if (tabs.isEmpty() && data.url) {
    browserUI.navigate(tabs.getSelected(), data.url)
  } else {
    var newIndex = tabs.getIndex(tabs.getSelected()) + 1
    var newTab = tabs.add({
      url: data.url || ''
    }, newIndex)

    browserUI.addTab(newTab, {
      enterEditMode: !data.url // only enter edit mode if the new tab is about:blank
    })
  }
})

ipc.on('saveCurrentPage', function () {
  var currentTab = tabs.get(tabs.getSelected())

  // new tabs cannot be saved
  if (!currentTab.url) {
    return
  }

  // if the current tab is a PDF, let the PDF viewer handle saving the document
  if (PDFViewer.isPDFViewer(tabs.getSelected())) {
    PDFViewer.savePDF(tabs.getSelected())
    return
  }

  var savePath = remote.dialog.showSaveDialog(remote.getCurrentWindow(), {})

  // savePath will be undefined if the save dialog is canceled
  if (savePath) {
    if (!savePath.endsWith('.html')) {
      savePath = savePath + '.html'
    }
    webviews.get(currentTab.id).savePage(savePath, 'HTMLComplete', function () {})
  }
})

function addPrivateTab () {
  /* new tabs can't be created in focus mode */
  if (focusMode.enabled()) {
    focusMode.warn()
    return
  }

  if (tabs.isEmpty()) {
    browserUI.destroyTab(tabs.getAtIndex(0).id)
  }

  var newIndex = tabs.getIndex(tabs.getSelected()) + 1

  var privateTab = tabs.add({
    private: true
  }, newIndex)
  browserUI.addTab(privateTab)
}

ipc.on('addPrivateTab', addPrivateTab)

ipc.on('addTask', function () {
  /* new tasks can't be created in focus mode */
  if (focusMode.enabled()) {
    focusMode.warn()
    return
  }

  browserUI.addTask()
  taskOverlay.show()
  setTimeout(function () {
    taskOverlay.hide()
    tabBar.enterEditMode(tabs.getSelected())
  }, 600)<commit_msg>change new tab behavior for private tabs<commit_after>/* defines keybindings that aren't in the menu (so they aren't defined by menu.js). For items in the menu, also handles ipc messages */

/*
There are three possible ways that keybindings can be handled.
 Shortcuts that appear in the menubar are registered in main.js, and send IPC messages to the window (which are handled by this file)
Shortcuts that don't appear in the menubar are registered in this file, using defineShortcut(). 
 - If the browser UI is focused, these are handled by Mousetrap.
  - If a BrowserView is focused, these are handled by the before-input-event listener.
  */

const menuBarVisibility = require('menuBarVisibility.js')
var searchbar = require('searchbar/searchbar.js')
var browserUI = require('browserUI.js')
var focusMode = require('focusMode.js')
var urlParser = require('util/urlParser.js')

ipc.on('zoomIn', function () {
  webviewGestures.zoomWebviewIn(tabs.getSelected())
})

ipc.on('zoomOut', function () {
  webviewGestures.zoomWebviewOut(tabs.getSelected())
})

ipc.on('zoomReset', function () {
  webviewGestures.resetWebviewZoom(tabs.getSelected())
})

ipc.on('print', function () {
  if (PDFViewer.isPDFViewer(tabs.getSelected())) {
    PDFViewer.printPDF(tabs.getSelected())
  } else if (readerView.isReader(tabs.getSelected())) {
    readerView.printArticle(tabs.getSelected())
  } else {
    //TODO figure out why webContents.print() doesn't work in Electron 4
    webviews.get(tabs.getSelected()).executeJavaScript("window.print()")
  }
})

ipc.on('findInPage', function () {
  findinpage.start()
})

ipc.on('inspectPage', function () {
  webviews.get(tabs.getSelected()).openDevTools()
})

ipc.on('showReadingList', function () {
  // open the searchbar with "!readinglist " as the input
  tabBar.enterEditMode(tabs.getSelected(), '!readinglist ')
})

ipc.on('showBookmarks', function () {
  tabBar.enterEditMode(tabs.getSelected(), '!bookmarks ')
})

ipc.on('showHistory', function () {
  tabBar.enterEditMode(tabs.getSelected(), '!history ')
})

ipc.on('duplicateTab', function (e) {
  /* new tabs can't be created in focus mode */
  if (focusMode.enabled()) {
    focusMode.warn()
    return
  }

  // can't duplicate if tabs is empty 
  if (tabs.isEmpty()) {
    return
  }

  const newIndex = tabs.getIndex(tabs.getSelected()) + 1

  const sourceTab = tabs.get(tabs.getSelected())
  // strip tab id so that a new one is generated
  const newTab = tabs.add({...sourceTab, id: undefined}, newIndex)

  browserUI.addTab(newTab, { enterEditMode: false })
})

ipc.on('addTab', function (e, data) {
  /* new tabs can't be created in focus mode */
  if (focusMode.enabled()) {
    focusMode.warn()
    return
  }

  // if opening a URL (instead of adding an empty tab), and only an empty tab is open, navigate the current tab rather than creating another one
  if (tabs.isEmpty() && data.url) {
    browserUI.navigate(tabs.getSelected(), data.url)
  } else {
    var newIndex = tabs.getIndex(tabs.getSelected()) + 1
    var newTab = tabs.add({
      url: data.url || ''
    }, newIndex)

    browserUI.addTab(newTab, {
      enterEditMode: !data.url // only enter edit mode if the new tab is about:blank
    })
  }
})

ipc.on('saveCurrentPage', function () {
  var currentTab = tabs.get(tabs.getSelected())

  // new tabs cannot be saved
  if (!currentTab.url) {
    return
  }

  // if the current tab is a PDF, let the PDF viewer handle saving the document
  if (PDFViewer.isPDFViewer(tabs.getSelected())) {
    PDFViewer.savePDF(tabs.getSelected())
    return
  }

  var savePath = remote.dialog.showSaveDialog(remote.getCurrentWindow(), {})

  // savePath will be undefined if the save dialog is canceled
  if (savePath) {
    if (!savePath.endsWith('.html')) {
      savePath = savePath + '.html'
    }
    webviews.get(currentTab.id).savePage(savePath, 'HTMLComplete', function () {})
  }
})

function addPrivateTab () {
  /* new tabs can't be created in focus mode */
  if (focusMode.enabled()) {
    focusMode.warn()
    return
  }

  if (!tabs.get(tabs.getSelected()).url && !tabs.get(tabs.getSelected()).private) {
    browserUI.destroyTab(tabs.getSelected())
  }

  var newIndex = tabs.getIndex(tabs.getSelected()) + 1

  var privateTab = tabs.add({
    private: true
  }, newIndex)
  browserUI.addTab(privateTab)
}

ipc.on('addPrivateTab', addPrivateTab)

ipc.on('addTask', function () {
  /* new tasks can't be created in focus mode */
  if (focusMode.enabled()) {
    focusMode.warn()
    return
  }

  browserUI.addTask()
  taskOverlay.show()
  setTimeout(function () {
    taskOverlay.hide()
    tabBar.enterEditMode(tabs.getSelected())
  }, 600)
{'fraction_non_alphanumeric': 0.13744588744588745, 'fraction_numerical': 0.0016233766233766235, 'mean_word_length': 3.8055122204888194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1154142', 'n_tokens_mistral': 3024, 'n_tokens_neox': 2912, 'n_words': 788}