mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-04-11 21:29:26 +02:00
optionally insert space before image
This commit is contained in:
parent
c74475194d
commit
ebe0d7451e
@ -42,8 +42,22 @@ export default function useTextAreaUploadFile(
|
||||
const content = getText();
|
||||
const position = ref.current?.getCaretPosition();
|
||||
if (position !== undefined) {
|
||||
setText(content.slice(0, position) + imageUrl + " " + content.slice(position));
|
||||
} else setText(content + imageUrl + " ");
|
||||
let inject = imageUrl;
|
||||
|
||||
// add a space before
|
||||
if (position >= 1 && content.slice(position - 1, position) !== " ") inject = " " + inject;
|
||||
// add a space after
|
||||
if (position < content.length && content.slice(position, position + 1) !== " ") inject = inject + " ";
|
||||
|
||||
setText(content.slice(0, position) + inject + content.slice(position));
|
||||
} else {
|
||||
let inject = imageUrl;
|
||||
|
||||
// add a space before if there isn't one
|
||||
if (content.slice(content.length - 1) !== " ") inject = " " + inject;
|
||||
|
||||
setText(content + inject + " ");
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof Error) toast({ description: e.message, status: "error" });
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user