atom-editor-logger
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "atom-editor-logger", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Simple tool for Atom editors input logging.", | ||
@@ -11,3 +11,5 @@ "main": "./src/atom/main", | ||
"dependencies": { | ||
"atom-package-deps": "^2.1.3" | ||
"atom-package-deps": "^2.1.3", | ||
"underscore": "^1.8.2", | ||
"atom-text-typer": "*" | ||
}, | ||
@@ -14,0 +16,0 @@ "devDependencies": { |
"use strict"; | ||
/// <reference path="../../typings/main.d.ts" /> | ||
var fs = require("fs"); | ||
var _ = require("underscore"); | ||
var textTyper = require("atom-text-typer"); | ||
var fileDialogUtils = require("./fileDialogUtils"); | ||
@@ -8,7 +10,36 @@ var enabled = false; | ||
function subscribe(editor) { | ||
return editor.getBuffer().onDidChange(function (event) { | ||
var filePath = editor.getPath(); | ||
if (filePath.indexOf("player:") === 0) { | ||
return { | ||
dispose: function () { | ||
}, | ||
disposed: false | ||
}; | ||
} | ||
return editor.getBuffer().onWillChange(function (event) { | ||
if (enabled) { | ||
var clone = JSON.parse(JSON.stringify(event)); | ||
clone.from = editor.getPath(); | ||
records.push(clone); | ||
if (!event.newRange) { | ||
return; | ||
} | ||
var exists = _.find(records, function (record) { | ||
return record[0] === filePath; | ||
}); | ||
if (!exists) { | ||
var change = textTyper.generateInitialChange(filePath, editor.getText()); | ||
records.push(textTyper.changeToRecord(change)); | ||
} | ||
var change = new textTyper.Change(); | ||
change.from = filePath; | ||
change.newRange = { | ||
start: editor.getBuffer().characterIndexForPosition(event.newRange.start), | ||
end: editor.getBuffer().characterIndexForPosition(event.newRange.end) | ||
}; | ||
change.oldRange = { | ||
start: editor.getBuffer().characterIndexForPosition(event.oldRange.start), | ||
end: editor.getBuffer().characterIndexForPosition(event.oldRange.end) | ||
}; | ||
change.oldText = event.oldText; | ||
change.newText = event.newText; | ||
var record = textTyper.changeToRecord(change); | ||
records.push(record); | ||
} | ||
@@ -18,2 +49,51 @@ }); | ||
exports.subscribe = subscribe; | ||
function play() { | ||
var extensionFilter = { | ||
name: 'JSON', | ||
extensions: ['json'] | ||
}; | ||
var filePath = fileDialogUtils.openFileDialogModal("Select file to play", fileDialogUtils.getHome(), [extensionFilter])[0]; | ||
if (filePath) { | ||
var content = fs.readFileSync(filePath).toString(); | ||
playRecord(content); | ||
} | ||
} | ||
exports.play = play; | ||
var editors; | ||
var steps; | ||
function playRecord(content) { | ||
var typer = new textTyper.TextTyper(content); | ||
editors = {}; | ||
steps = []; | ||
addSingleStep(typer); | ||
while (typer.hasNext()) { | ||
typer.increment(); | ||
addSingleStep(typer); | ||
} | ||
playStep(0); | ||
} | ||
function playStep(index) { | ||
if (index === steps.length) { | ||
return; | ||
} | ||
showEditorWithContent(steps[index].filePath, steps[index].content); | ||
setTimeout(function () { return playStep(index + 1); }, 100); | ||
} | ||
function addSingleStep(typer) { | ||
var filePath = typer.currentContentPath(); | ||
steps.push({ | ||
filePath: filePath, | ||
content: typer.currentContent(filePath) | ||
}); | ||
} | ||
function showEditorWithContent(filePath, content) { | ||
var promise = editors[filePath]; | ||
if (!promise) { | ||
promise = atom.workspace.open("player:/" + filePath + ".log", {}); | ||
} | ||
editors[filePath] = promise.then(function (editor) { | ||
editor.setText(content); | ||
return editor; | ||
}); | ||
} | ||
function enable() { | ||
@@ -32,3 +112,3 @@ records = []; | ||
try { | ||
fs.writeFileSync(filePath, JSON.stringify(records, null, "\t")); | ||
fs.writeFileSync(filePath, JSON.stringify(records)); | ||
} | ||
@@ -35,0 +115,0 @@ catch (exception) { |
@@ -5,2 +5,6 @@ /// <reference path="../../typings/main.d.ts" /> | ||
import _ = require("underscore"); | ||
import textTyper = require("atom-text-typer"); | ||
import fileDialogUtils = require("./fileDialogUtils"); | ||
@@ -10,12 +14,53 @@ | ||
var records = []; | ||
var records: any[][] = []; | ||
export function subscribe(editor: AtomCore.IEditor): AtomCore.Disposable { | ||
return (<any>editor).getBuffer().onDidChange((event) => { | ||
var filePath = editor.getPath(); | ||
if(filePath.indexOf("player:") === 0) { | ||
return { | ||
dispose: () => { | ||
}, | ||
disposed: false | ||
}; | ||
} | ||
return (<any>editor).getBuffer().onWillChange((event) => { | ||
if(enabled) { | ||
var clone = JSON.parse(JSON.stringify(event)) | ||
if(!event.newRange) { | ||
return; | ||
} | ||
var exists = _.find(records, (record: any[]) => { | ||
return record[0] === filePath; | ||
}); | ||
if(!exists) { | ||
var change = textTyper.generateInitialChange(filePath, editor.getText()); | ||
clone.from = editor.getPath(); | ||
records.push(clone); | ||
records.push(textTyper.changeToRecord(change)); | ||
} | ||
var change = new textTyper.Change(); | ||
change.from = filePath; | ||
change.newRange = { | ||
start: editor.getBuffer().characterIndexForPosition(event.newRange.start), | ||
end: editor.getBuffer().characterIndexForPosition(event.newRange.end) | ||
}; | ||
change.oldRange = { | ||
start: editor.getBuffer().characterIndexForPosition(event.oldRange.start), | ||
end: editor.getBuffer().characterIndexForPosition(event.oldRange.end) | ||
}; | ||
change.oldText = event.oldText; | ||
change.newText = event.newText; | ||
var record = textTyper.changeToRecord(change); | ||
records.push(record); | ||
} | ||
@@ -25,2 +70,72 @@ }); | ||
export function play(): void { | ||
var extensionFilter: any = { | ||
name: 'JSON', | ||
extensions: ['json'] | ||
}; | ||
var filePath = fileDialogUtils.openFileDialogModal("Select file to play", fileDialogUtils.getHome(), [extensionFilter])[0]; | ||
if(filePath) { | ||
var content = fs.readFileSync(filePath).toString(); | ||
playRecord(content); | ||
} | ||
} | ||
var editors; | ||
var steps; | ||
function playRecord(content: string): void { | ||
var typer = new textTyper.TextTyper(content); | ||
editors = {}; | ||
steps = []; | ||
addSingleStep(typer); | ||
while(typer.hasNext()) { | ||
typer.increment(); | ||
addSingleStep(typer); | ||
} | ||
playStep(0); | ||
} | ||
function playStep(index) { | ||
if(index === steps.length) { | ||
return; | ||
} | ||
showEditorWithContent(steps[index].filePath, steps[index].content); | ||
setTimeout(() => playStep(index + 1), 100); | ||
} | ||
function addSingleStep(typer): void { | ||
var filePath = typer.currentContentPath(); | ||
steps.push({ | ||
filePath: filePath, | ||
content: typer.currentContent(filePath) | ||
}) | ||
} | ||
function showEditorWithContent(filePath, content): void { | ||
var promise = editors[filePath]; | ||
if(!promise) { | ||
promise = atom.workspace.open("player:/" + filePath + ".log", {}); | ||
} | ||
editors[filePath] = promise.then(editor => { | ||
(<any>editor).setText(content); | ||
return editor; | ||
}); | ||
} | ||
export function enable(): void { | ||
@@ -36,9 +151,9 @@ records = []; | ||
extensions: ['json'] | ||
} | ||
}; | ||
var filePath = fileDialogUtils.saveFileDialogModal("Save editors log", fileDialogUtils.getHome(), [extensionFilter]); | ||
var filePath = fileDialogUtils.saveFileDialogModal("Save editors log", fileDialogUtils.getHome(), [extensionFilter]); | ||
if(filePath) { | ||
try { | ||
fs.writeFileSync(filePath, JSON.stringify(records, null, "\t")) | ||
fs.writeFileSync(filePath, JSON.stringify(records)); | ||
} catch(exception) { | ||
@@ -48,3 +163,3 @@ | ||
} | ||
records = []; | ||
@@ -51,0 +166,0 @@ |
@@ -12,3 +12,4 @@ "use strict"; | ||
'atom-editor-logger:start-logging': function () { return logger.enable(); }, | ||
'atom-editor-logger:stop-logging': function () { return logger.disable(); } | ||
'atom-editor-logger:stop-logging': function () { return logger.disable(); }, | ||
'atom-editor-logger:play-sequence': function () { return logger.play(); } | ||
})); | ||
@@ -15,0 +16,0 @@ }); |
@@ -13,3 +13,4 @@ /// <reference path="../../typings/main.d.ts" /> | ||
'atom-editor-logger:start-logging': () => logger.enable(), | ||
'atom-editor-logger:stop-logging': () => logger.disable() | ||
'atom-editor-logger:stop-logging': () => logger.disable(), | ||
'atom-editor-logger:play-sequence': () => logger.play() | ||
})); | ||
@@ -16,0 +17,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
24234
3
11
449
3
0
1
+ Addedatom-text-typer@*
+ Addedunderscore@^1.8.2
+ Addedatom-text-typer@0.0.1(transitive)
+ Addedunderscore@1.13.7(transitive)