Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

atom-editor-logger

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atom-editor-logger - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

6

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc