mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2025-09-24 16:40:55 -06:00
add basic insertAtCursor
This commit is contained in:
parent
85ecc582b4
commit
6fbf38f6ba
File diff suppressed because one or more lines are too long
@ -16357,6 +16357,24 @@ function drawLink(editor) {
|
||||
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert image at cursor
|
||||
*/
|
||||
function insertAtCursor(cm, text, url, desc, point) {
|
||||
var start = text[0];
|
||||
var end = text[1];
|
||||
if(typeof point != "undefined") {
|
||||
point = cm.coordsChar(point);
|
||||
} else {
|
||||
point = cm.getCursor("start");
|
||||
}
|
||||
start = start.replace("#desc#", desc);
|
||||
end = end.replace("#url#", url);
|
||||
cm.replaceRange(start + end, point);
|
||||
cm.focus();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action for drawing an img.
|
||||
*/
|
||||
@ -16364,7 +16382,6 @@ function drawImage(editor, url, desc) {
|
||||
url = (typeof url != "undefined") ? url : "http://";
|
||||
desc = (typeof desc != "undefined") ? desc : "";
|
||||
var cm = editor.codemirror;
|
||||
var stat = getState(cm);
|
||||
var options = editor.options;
|
||||
if(options.promptURLs) {
|
||||
url = prompt(options.promptTexts.image);
|
||||
@ -16372,7 +16389,7 @@ function drawImage(editor, url, desc) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_replaceSelection(cm, stat.image, options.insertTexts.image, url, desc);
|
||||
insertAtCursor(cm, options.insertTexts.image, url, desc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
2
dist/simplemde.min.js
vendored
2
dist/simplemde.min.js
vendored
File diff suppressed because one or more lines are too long
@ -627,6 +627,24 @@ function drawLink(editor) {
|
||||
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert image at cursor
|
||||
*/
|
||||
function insertAtCursor(cm, text, url, desc, point) {
|
||||
var start = text[0];
|
||||
var end = text[1];
|
||||
if(typeof point != "undefined") {
|
||||
point = cm.coordsChar(point);
|
||||
} else {
|
||||
point = cm.getCursor("start");
|
||||
}
|
||||
start = start.replace("#desc#", desc);
|
||||
end = end.replace("#url#", url);
|
||||
cm.replaceRange(start + end, point);
|
||||
cm.focus();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action for drawing an img.
|
||||
*/
|
||||
@ -634,7 +652,6 @@ function drawImage(editor, url, desc) {
|
||||
url = (typeof url != "undefined") ? url : "http://";
|
||||
desc = (typeof desc != "undefined") ? desc : "";
|
||||
var cm = editor.codemirror;
|
||||
var stat = getState(cm);
|
||||
var options = editor.options;
|
||||
if(options.promptURLs) {
|
||||
url = prompt(options.promptTexts.image);
|
||||
@ -642,7 +659,7 @@ function drawImage(editor, url, desc) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_replaceSelection(cm, stat.image, options.insertTexts.image, url, desc);
|
||||
insertAtCursor(cm, options.insertTexts.image, url, desc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user