Skip to content

Commit

Permalink
#15 higher debounce time when using gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Almenon committed Feb 10, 2018
1 parent cebf655 commit b0a2f4b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"vscode": "^1.1.10"
},
"dependencies": {
"arepl-backend": "^1.0.0-alpha.6",
"arepl-backend": "^1.0.0-alpha.7",
"opn": "^4.0.2",
"path": "^0.12.7",
"python-shell": "^0.4.0"
Expand Down
15 changes: 11 additions & 4 deletions src/PreviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {PythonEvaluator} from 'arepl-backend'
// This class initializes the previewmanager based on extension type and manages all the subscriptions
export default class PreviewManager {

restartMode: boolean;
pythonPreviewContentProvider: HtmlDocumentContentProvider;
disposable: vscode.Disposable;
pythonEditor: vscode.TextDocument;
Expand All @@ -25,6 +26,8 @@ export default class PreviewManager {
// python
/////////////////////////////////////////////////////////
let self:PreviewManager = this;
let debounce = 300;
let restartExtraDebounce = 300;

this.pythonEvaluator.startPython()
this.pythonEvaluator.pyshell.childProcess.on('error', err => {
Expand All @@ -42,7 +45,10 @@ export default class PreviewManager {

let subscriptions: vscode.Disposable[] = [];
this.disposable = vscode.Disposable.from(...subscriptions);
vscode.workspace.onDidChangeTextDocument(this.onUserInput, this, subscriptions);
vscode.workspace.onDidChangeTextDocument((e)=>{
let delay = this.restartMode ? debounce + restartExtraDebounce : debounce
this.pythonEvaluator.debounce(this.onUserInput.bind(this,e), delay)
}, this, subscriptions);

vscode.workspace.onDidCloseTextDocument((e)=>{
if(e == this.pythonEditor || e.uri.scheme == HtmlDocumentContentProvider.scheme) this.dispose()
Expand Down Expand Up @@ -72,7 +78,6 @@ export default class PreviewManager {
this.disposable.dispose();
}

@debounce(300)
private onUserInput(event: vscode.TextDocumentChangeEvent) {
if(event.document == this.pythonEditor){
let text = event.document.getText();
Expand All @@ -91,8 +96,10 @@ export default class PreviewManager {
evalCode: codeLines.join('\n')
}

if(pyGuiLibraryIsPresent(text)){

this.restartMode = pyGuiLibraryIsPresent(text)

if(this.restartMode){

let fileName = event.document.fileName
let syntaxPromise: Promise<{}>

Expand Down

0 comments on commit b0a2f4b

Please # to comment.