Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up link insertion after uploads to be saner #3011

Merged
merged 1 commit into from Feb 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions client/js/socket-events/uploads.js
@@ -1,10 +1,24 @@
"use strict";

const socket = require("../socket");
const wrapCursor = require("undate").wrapCursor;
const updateCursor = require("undate").update;

socket.on("upload:success", (url) => {
const fullURL = new URL(url, location);
const fullURL = (new URL(url, location)).toString();
const textbox = document.getElementById("input");
wrapCursor(textbox, fullURL, " ");
const initStart = textbox.selectionStart;

// Get the text before the cursor, and add a space if it's not in the beginning
const headToCursor = initStart > 0 ? (textbox.value.substr(0, initStart) + " ") : "";

// Get the remaining text after the cursor
const cursorToTail = textbox.value.substr(initStart);

// Construct the value until the point where we want the cursor to be
const textBeforeTail = headToCursor + fullURL + " ";

updateCursor(textbox, textBeforeTail + cursorToTail);

// Set the cursor after the link and a space
textbox.selectionStart = textbox.selectionEnd = textBeforeTail.length;
});