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] Added plain text pasting and fixed issues with image pasting. #169

Closed
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6a0370e
Merge remote-tracking branch 'upstream/main'
Oct 28, 2024
6a66cdd
Merge remote-tracking branch 'upstream/main'
Oct 28, 2024
134340a
Merge remote-tracking branch 'upstream/main'
charlwillia6 Oct 29, 2024
3f07de8
Merge remote-tracking branch 'upstream/main'
charlwillia6 Oct 30, 2024
8f7f236
Merge remote-tracking branch 'upstream/main'
charlwillia6 Oct 30, 2024
447600c
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 1, 2024
02b8de3
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 2, 2024
99f66ae
Merge remote-tracking branch 'upstream/main'
Nov 4, 2024
527e486
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 7, 2024
a0e9d50
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 8, 2024
b907905
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 10, 2024
0b5244d
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 11, 2024
7e47d71
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 11, 2024
0df9372
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 12, 2024
ab14a70
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 14, 2024
a4eed44
Merge remote-tracking branch 'upstream/main'
charlwillia6 Nov 15, 2024
a0b7d00
Fix: improve image and text paste handling in TipTapEditor
charlwillia6 Nov 15, 2024
5332300
Updated message
charlwillia6 Nov 15, 2024
1a73392
Merge remote-tracking branch 'upstream/main' into charlwillia6/fix-is…
charlwillia6 Nov 17, 2024
5b6c83a
Fixed image positioning and a bug where newlines were being removed w…
charlwillia6 Nov 17, 2024
5ef8491
delete selected text
Himanshu-Singh-Chauhan Nov 17, 2024
48228dd
Remove console log
Fryingpannn Nov 18, 2024
b3d28d8
Merge branch 'charlwillia6/fix-issues-with-pasting' of https://github…
Himanshu-Singh-Chauhan Nov 18, 2024
9605785
Merge remote-tracking branch 'upstream/main' into charlwillia6/fix-is…
charlwillia6 Nov 18, 2024
6fc0727
Merge remote-tracking branch 'upstream/main' into charlwillia6/fix-is…
charlwillia6 Nov 20, 2024
50e63bd
Found a bug when pasting images with CTRL+V
charlwillia6 Nov 24, 2024
22aa59b
Updated useEffect so that the paste handlers handle paste operations
charlwillia6 Nov 24, 2024
183c2ad
Removed extra spaces.
charlwillia6 Nov 24, 2024
448ac93
Combined logic into one paste handler.
charlwillia6 Nov 24, 2024
e6d8366
Removed spaces
charlwillia6 Nov 24, 2024
5958a26
Merge remote-tracking branch 'upstream/main' into charlwillia6/fix-is…
charlwillia6 Nov 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 58 additions & 19 deletions gui/src/components/mainInput/TipTapEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import ActiveFileIndicator from "./ActiveFileIndicator";
import { setActiveFilePath } from "@/redux/slices/uiStateSlice";
import TopBar from "./TopBarIndicators";
import { isAiderMode, isPerplexityMode } from "../../util/bareChatMode";

import HardBreak from '@tiptap/extension-hard-break';

const InputBoxDiv = styled.div`
resize: none;
Expand Down Expand Up @@ -327,31 +327,44 @@ const TipTapEditor = memo(function TipTapEditor({
props: {
handleDOMEvents: {
paste(view, event) {
console.log("Pasting image");
const items = event.clipboardData.items;
for (const item of items) {
const file = item.getAsFile();
file &&
modelSupportsImages(

const hasImageItem = Array.from(items).some(
item => item.type.startsWith('image/')
);

// Only log and process if we actually have an image
if (hasImageItem) {
console.log("Pasting image");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console log!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already in the code. I only moved it to inside this logic. @Fryingpannn do you want me to delete it?

for (const item of items) {
if (!item.type.startsWith('image/')) continue;

const file = item.getAsFile();
if (!file) continue;

if (modelSupportsImages(
defaultModel.provider,
defaultModel.model,
defaultModel.title,
defaultModel.capabilities,
) &&
handleImageFile(file).then((resp) => {
if (!resp) {
return;
}
const [img, dataUrl] = resp;
const { schema } = view.state;
const node = schema.nodes.image.create({
src: dataUrl,
)) {
event.preventDefault();

handleImageFile(file).then((resp) => {
if (!resp) return;

const [img, dataUrl] = resp;
const { schema } = view.state;
const node = schema.nodes.image.create({
src: dataUrl,
});
const tr = view.state.tr.insert(0, node);
view.dispatch(tr);
});
const tr = view.state.tr.insert(0, node);
view.dispatch(tr);
});
}
}
}
},
}
},
},
});
Expand Down Expand Up @@ -451,6 +464,7 @@ const TipTapEditor = memo(function TipTapEditor({
},
}),
Text,
HardBreak,
Mention.configure({
HTMLAttributes: {
class: "mention",
Expand Down Expand Up @@ -489,6 +503,31 @@ const TipTapEditor = memo(function TipTapEditor({
class: "outline-none -mt-1 mb-1 overflow-hidden",
style: `font-size: ${getFontSize()}px;`,
},
handlePaste(view, event) {
const items = event.clipboardData.items;
const hasImageItem = Array.from(items).some(item => item.type.startsWith('image/'));

if (!hasImageItem) {
event.preventDefault();
const text = event.clipboardData.getData('text/plain');
const lines = text.split(/\r?\n/);
const { tr } = view.state;
const { schema } = view.state;
let pos = view.state.selection.from;

lines.forEach((line, index) => {
if (index > 0) {
tr.insert(pos++, schema.nodes.hardBreak.create());
}
tr.insertText(line, pos);
pos += line.length;
});

view.dispatch(tr);
return true;
}
return false;
},
},
content: lastContentRef.current,
editable: true,
Expand Down