From caa414f6a908eeca9ce5af711dc544b292dc2461 Mon Sep 17 00:00:00 2001 From: Oleksandr Bardanov Date: Wed, 27 Aug 2014 11:00:36 +0300 Subject: [PATCH] insert at caret position, fix #2 --- package.json | 2 +- templates/modal.html | 1 + viewmodels/modalViewModel.js | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 153f8e6..3f2e8b0 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "title": "Lorem Pixel", "description": "Generate placeholder Images for every case", "homepage": "https://github.com/dnbard/brackets-lorem-pixel", - "version": "0.1.2", + "version": "0.1.3", "author": "Alex Bardanov", "license": "MIT", "engines": { diff --git a/templates/modal.html b/templates/modal.html index e6e1f6b..9f2fd65 100644 --- a/templates/modal.html +++ b/templates/modal.html @@ -49,6 +49,7 @@

Lorem pixel

diff --git a/viewmodels/modalViewModel.js b/viewmodels/modalViewModel.js index 34951fd..2bfa236 100644 --- a/viewmodels/modalViewModel.js +++ b/viewmodels/modalViewModel.js @@ -4,6 +4,8 @@ define(function(require, exports, module){ fs = require('../services/filesystem'), ExtensionUtils = brackets.getModule("utils/ExtensionUtils"), NodeConnection = brackets.getModule("utils/NodeConnection"), + DocumentManager = brackets.getModule("document/DocumentManager"), + EditorManager = brackets.getModule("editor/EditorManager"), nodeConnection = new NodeConnection(); function chain() { @@ -83,6 +85,20 @@ define(function(require, exports, module){ nodeConnection.domains.clipboard.callCopy(this.url()); }, this); + this.onUrlInsert = _.bind(function(model, event){ + var currentDoc = DocumentManager.getCurrentDocument(), + editor = EditorManager.getCurrentFullEditor(), + pos = editor.getCursorPos(), + posEnd; + + currentDoc.replaceRange(this.url(), pos); + posEnd = $.extend({}, pos); + posEnd.ch += this.url().length; + + editor.focus(); + editor.setSelection(pos, posEnd); + }, this); + this.onFileSave = function(){ fs.showSaveDialog(function(opt, path){ var data = atob(getBase64Image($('.preview-box > img')[0]));