-
-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
350 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 46 additions & 3 deletions
49
packages/ui-plugin-docs/src/controllers/clipboard.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,63 @@ | ||
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core'; | ||
import { ITextSelectionRenderManager } from '@univerjs/base-render'; | ||
import { Disposable, ICommandInfo, ICommandService, ILogService, IUniverInstanceService } from '@univerjs/core'; | ||
|
||
import { DocCopyCommand, DocCutCommand, DocPasteCommand } from '../commands/commands/clipboard.command'; | ||
import { | ||
DocCopyCommand, | ||
DocCutCommand, | ||
DocPasteCommand, | ||
InnerPasteCommand, | ||
} from '../commands/commands/clipboard.command'; | ||
import { IDocClipboardService } from '../services/clipboard/clipboard.service'; | ||
|
||
export class DocClipboardController extends Disposable { | ||
constructor( | ||
@ILogService private readonly _logService: ILogService, | ||
@ICommandService private readonly _commandService: ICommandService, | ||
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService, | ||
@IDocClipboardService private readonly _docClipboardService: IDocClipboardService | ||
@IDocClipboardService private readonly _docClipboardService: IDocClipboardService, | ||
@ITextSelectionRenderManager private _textSelectionRenderManager: ITextSelectionRenderManager | ||
) { | ||
super(); | ||
this.commandExecutedListener(); | ||
} | ||
|
||
initialize() { | ||
[DocCopyCommand, DocCutCommand, DocPasteCommand].forEach((command) => | ||
this.disposeWithMe(this._commandService.registerAsMultipleCommand(command)) | ||
); | ||
[InnerPasteCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command))); | ||
} | ||
|
||
private commandExecutedListener() { | ||
const updateCommandList = [DocPasteCommand.id]; | ||
|
||
this.disposeWithMe( | ||
this._commandService.onCommandExecuted((command: ICommandInfo) => { | ||
if (!updateCommandList.includes(command.id)) { | ||
return; | ||
} | ||
|
||
this.handlePaste(); | ||
}) | ||
); | ||
} | ||
|
||
private async handlePaste() { | ||
const { _docClipboardService: docClipboardService } = this; | ||
const { segmentId } = this._textSelectionRenderManager.getActiveRange() ?? {}; | ||
|
||
if (!segmentId) { | ||
this._logService.error('[DocClipboardController] segmentId is not existed'); | ||
} | ||
|
||
try { | ||
const body = await docClipboardService.queryClipboardData(); | ||
|
||
this._commandService.executeCommand(InnerPasteCommand.id, { body, segmentId }); | ||
|
||
// TODO: @jocs, reset selections. | ||
} catch (_e) { | ||
this._logService.error('[DocClipboardController] clipboard is empty'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.