Skip to content

Commit

Permalink
insert at caret position, fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Bardanov committed Aug 27, 2014
1 parent 27e017d commit caa414f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions templates/modal.html
Expand Up @@ -49,6 +49,7 @@ <h1 class="dialog-title">Lorem pixel</h1>
<div class="modal-footer">
<button class="dialog-button btn primary" data-button-id="ok">Close</button>
<button class="dialog-button btn" data-bind="click: onUrlCopy">Copy url to clipboard</button>
<button class="dialog-button btn" data-bind="click: onUrlInsert">Insert at caret position</button>
<button class="dialog-button btn" data-bind="click: onPreview">Preview</button>
</div>
</div>
16 changes: 16 additions & 0 deletions viewmodels/modalViewModel.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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]));
Expand Down

0 comments on commit caa414f

Please sign in to comment.