mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Merge pull request #12439 from remexre/master
Adds configuration option for large file warning threshold.
This commit is contained in:
@@ -432,9 +432,9 @@ describe "Workspace", ->
|
||||
runs ->
|
||||
expect(editor.largeFileMode).toBe true
|
||||
|
||||
describe "when the file is over 20MB", ->
|
||||
it "prompts the user to make sure they want to open a file this big", ->
|
||||
spyOn(fs, 'getSizeSync').andReturn 20 * 1048577 # 20MB
|
||||
describe "when the file is over user-defined limit", ->
|
||||
shouldPromptForFileOfSize = (size, shouldPrompt) ->
|
||||
spyOn(fs, 'getSizeSync').andReturn size * 1048577
|
||||
atom.applicationDelegate.confirm.andCallFake -> selectedButtonIndex
|
||||
atom.applicationDelegate.confirm()
|
||||
selectedButtonIndex = 1 # cancel
|
||||
@@ -442,20 +442,35 @@ describe "Workspace", ->
|
||||
editor = null
|
||||
waitsForPromise ->
|
||||
workspace.open('sample.js').then (e) -> editor = e
|
||||
if shouldPrompt
|
||||
runs ->
|
||||
expect(editor).toBeUndefined()
|
||||
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
||||
|
||||
runs ->
|
||||
expect(editor).toBeUndefined()
|
||||
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
||||
atom.applicationDelegate.confirm.reset()
|
||||
selectedButtonIndex = 0 # open the file
|
||||
|
||||
atom.applicationDelegate.confirm.reset()
|
||||
selectedButtonIndex = 0 # open the file
|
||||
waitsForPromise ->
|
||||
workspace.open('sample.js').then (e) -> editor = e
|
||||
|
||||
waitsForPromise ->
|
||||
workspace.open('sample.js').then (e) -> editor = e
|
||||
runs ->
|
||||
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
||||
expect(editor.largeFileMode).toBe true
|
||||
else
|
||||
runs ->
|
||||
expect(editor).not.toBeUndefined()
|
||||
|
||||
runs ->
|
||||
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
||||
expect(editor.largeFileMode).toBe true
|
||||
it "prompts the user to make sure they want to open a file this big", ->
|
||||
atom.config.set "core.warnOnLargeFileLimit", 20
|
||||
shouldPromptForFileOfSize 20, true
|
||||
|
||||
it "doesn't prompt on files below the limit", ->
|
||||
atom.config.set "core.warnOnLargeFileLimit", 30
|
||||
shouldPromptForFileOfSize 20, false
|
||||
|
||||
it "prompts for smaller files with a lower limit", ->
|
||||
atom.config.set "core.warnOnLargeFileLimit", 5
|
||||
shouldPromptForFileOfSize 10, true
|
||||
|
||||
describe "when passed a path that matches a custom opener", ->
|
||||
it "returns the resource returned by the custom opener", ->
|
||||
|
||||
@@ -122,6 +122,10 @@ module.exports =
|
||||
{value: 'no', description: 'Do not send any telemetry data'}
|
||||
{value: 'undecided', description: 'Undecided (Atom will ask again next time it is launched)'}
|
||||
]
|
||||
warnOnLargeFileLimit:
|
||||
description: 'Warn before opening files larger than this number of megabytes.'
|
||||
type: 'number'
|
||||
default: 20
|
||||
editor:
|
||||
type: 'object'
|
||||
properties:
|
||||
|
||||
@@ -550,7 +550,7 @@ class Workspace extends Model
|
||||
fileSize = fs.getSizeSync(filePath)
|
||||
|
||||
largeFileMode = fileSize >= 2 * 1048576 # 2MB
|
||||
if fileSize >= 20 * 1048576 # 20MB
|
||||
if fileSize >= @config.get('core.warnOnLargeFileLimit') * 1048576 # 20MB by default
|
||||
choice = @applicationDelegate.confirm
|
||||
message: 'Atom will be unresponsive during the loading of very large files.'
|
||||
detailedMessage: "Do you still want to load this file?"
|
||||
|
||||
Reference in New Issue
Block a user