11// Copyright 2025, Command Line Inc.
22// SPDX-License-Identifier: Apache-2.0
33
4-
54import { BlockNodeModel } from "@/app/block/blocktypes" ;
65import { appHandleKeyDown } from "@/app/store/keymodel" ;
76import { waveEventSubscribe } from "@/app/store/wps" ;
@@ -15,6 +14,7 @@ import { WorkspaceLayoutModel } from "@/app/workspace/workspace-layout-model";
1514import {
1615 atoms ,
1716 getAllBlockComponentModels ,
17+ getApi ,
1818 getBlockComponentModel ,
1919 getBlockMetaKeyAtom ,
2020 getConnStatusAtom ,
@@ -29,22 +29,15 @@ import * as keyutil from "@/util/keyutil";
2929import { boundNumber , stringToBase64 } from "@/util/util" ;
3030import * as jotai from "jotai" ;
3131import * as React from "react" ;
32- import {
33- computeTheme ,
34- createTempFileFromBlob ,
35- DefaultTermTheme ,
36- handleImagePasteBlob as handleImagePasteBlobUtil ,
37- supportsImageInput as supportsImageInputUtil ,
38- } from "./termutil" ;
39- import { TermWrap } from "./termwrap" ;
4032import { getBlockingCommand } from "./shellblocking" ;
33+ import { computeTheme , DefaultTermTheme } from "./termutil" ;
34+ import { TermWrap } from "./termwrap" ;
4135
4236export class TermViewModel implements ViewModel {
43-
4437 viewType : string ;
4538 nodeModel : BlockNodeModel ;
4639 connected : boolean ;
47- termRef : React . MutableRefObject < TermWrap > = { current : null } ;
40+ termRef : React . RefObject < TermWrap > = { current : null } ;
4841 blockAtom : jotai . Atom < Block > ;
4942 termMode : jotai . Atom < string > ;
5043 blockId : string ;
@@ -398,51 +391,6 @@ export class TermViewModel implements ViewModel {
398391 RpcApi . ControllerInputCommand ( TabRpcClient , { blockid : this . blockId , inputdata64 : b64data } ) ;
399392 }
400393
401- async handlePaste ( ) {
402- try {
403- const clipboardItems = await navigator . clipboard . read ( ) ;
404-
405- for ( const item of clipboardItems ) {
406- // Check for images first
407- const imageTypes = item . types . filter ( ( type ) => type . startsWith ( "image/" ) ) ;
408- if ( imageTypes . length > 0 && this . supportsImageInput ( ) ) {
409- const blob = await item . getType ( imageTypes [ 0 ] ) ;
410- await this . handleImagePasteBlob ( blob ) ;
411- return ;
412- }
413-
414- // Handle text
415- if ( item . types . includes ( "text/plain" ) ) {
416- const blob = await item . getType ( "text/plain" ) ;
417- const text = await blob . text ( ) ;
418- this . termRef . current ?. terminal . paste ( text ) ;
419- return ;
420- }
421- }
422- } catch ( err ) {
423- console . error ( "Paste error:" , err ) ;
424- // Fallback to text-only paste
425- try {
426- const text = await navigator . clipboard . readText ( ) ;
427- if ( text ) {
428- this . termRef . current ?. terminal . paste ( text ) ;
429- }
430- } catch ( fallbackErr ) {
431- console . error ( "Fallback paste error:" , fallbackErr ) ;
432- }
433- }
434- }
435-
436- supportsImageInput ( ) : boolean {
437- return supportsImageInputUtil ( ) ;
438- }
439-
440- async handleImagePasteBlob ( blob : Blob ) : Promise < void > {
441- await handleImagePasteBlobUtil ( blob , TabRpcClient , ( text ) => {
442- this . termRef . current ?. terminal . paste ( text ) ;
443- } ) ;
444- }
445-
446394 setTermMode ( mode : "term" | "vdom" ) {
447395 if ( mode == "term" ) {
448396 mode = null ;
@@ -559,22 +507,26 @@ export class TermViewModel implements ViewModel {
559507 const shiftEnterNewlineAtom = getOverrideConfigAtom ( this . blockId , "term:shiftenternewline" ) ;
560508 const shiftEnterNewlineEnabled = globalStore . get ( shiftEnterNewlineAtom ) ?? true ;
561509 if ( shiftEnterNewlineEnabled ) {
562- this . sendDataToController ( "\u001b\ n" ) ;
510+ this . sendDataToController ( "\n" ) ;
563511 event . preventDefault ( ) ;
564512 event . stopPropagation ( ) ;
565513 return false ;
566514 }
567515 }
568516 if ( keyutil . checkKeyPressed ( waveEvent , "Ctrl:Shift:v" ) ) {
569- this . handlePaste ( ) ;
570517 event . preventDefault ( ) ;
571518 event . stopPropagation ( ) ;
519+ getApi ( ) . nativePaste ( ) ;
520+ // this.termRef.current?.pasteHandler();
572521 return false ;
573522 } else if ( keyutil . checkKeyPressed ( waveEvent , "Ctrl:Shift:c" ) ) {
574- const sel = this . termRef . current ?. terminal . getSelection ( ) ;
575- navigator . clipboard . writeText ( sel ) ;
576523 event . preventDefault ( ) ;
577524 event . stopPropagation ( ) ;
525+ const sel = this . termRef . current ?. terminal . getSelection ( ) ;
526+ if ( ! sel ) {
527+ return false ;
528+ }
529+ navigator . clipboard . writeText ( sel ) ;
578530 return false ;
579531 } else if ( keyutil . checkKeyPressed ( waveEvent , "Cmd:k" ) ) {
580532 event . preventDefault ( ) ;
0 commit comments