improve paste implementation
This commit is contained in:
@@ -15,6 +15,6 @@ namespace FluentTerminal.App.ViewModels
|
||||
Task FindPreviousAsync(SearchRequest request);
|
||||
Task FocusTerminalAsync();
|
||||
Task<string> SerializeXtermStateAsync();
|
||||
Task PasteAsync(string text);
|
||||
void Paste(string text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,7 +634,7 @@ namespace FluentTerminal.App.ViewModels
|
||||
if (content != null)
|
||||
{
|
||||
content = ShellProfile.NewlinePattern.Replace(content, string.Empty);
|
||||
await TerminalView.PasteAsync(content).ConfigureAwait(false);
|
||||
TerminalView.Paste(content);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -710,7 +710,7 @@ namespace FluentTerminal.App.ViewModels
|
||||
if (content != null)
|
||||
{
|
||||
content = ShellProfile.TranslateLineEndings(content);
|
||||
await TerminalView.PasteAsync(content).ConfigureAwait(false);
|
||||
TerminalView.Paste(content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
using FluentTerminal.App.Converters;
|
||||
using FluentTerminal.App.Services;
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
using FluentTerminal.App.Utilities;
|
||||
using FluentTerminal.App.ViewModels;
|
||||
using FluentTerminal.App.ViewModels.Menu;
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using FluentTerminal.RuntimeComponent.Enums;
|
||||
using FluentTerminal.RuntimeComponent.Interfaces;
|
||||
using FluentTerminal.RuntimeComponent.WebAllowedObjects;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Windows.Foundation;
|
||||
using Windows.System;
|
||||
using Windows.UI;
|
||||
@@ -122,6 +117,7 @@ namespace FluentTerminal.App.Views
|
||||
#endregion Resize handling
|
||||
|
||||
public event EventHandler<object> OnOutput;
|
||||
public event EventHandler<string> OnPaste;
|
||||
|
||||
public XtermTerminalView()
|
||||
{
|
||||
@@ -556,7 +552,6 @@ namespace FluentTerminal.App.Views
|
||||
_outputBlockedBuffer?.Dispose();
|
||||
}
|
||||
|
||||
public Task PasteAsync(string text) => ExecuteScriptAsync(
|
||||
$"window.term.paste('{text.Replace(@"\", @"\\").Replace("'", @"\'").Replace("\n", @"\n").Replace("\r", @"\r")}')");
|
||||
public void Paste(string text) => OnPaste?.Invoke(this, text);
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,10 @@ window.createTerminal = (options, theme, keyBindings) => {
|
||||
term.writeUtf8(data);
|
||||
});
|
||||
|
||||
window.terminalBridge.onpaste = (text => {
|
||||
term.paste(text);
|
||||
});
|
||||
|
||||
term.onData(data => {
|
||||
window.terminalBridge.inputReceived(data);
|
||||
});
|
||||
|
||||
@@ -23,5 +23,6 @@ namespace FluentTerminal.RuntimeComponent.Interfaces
|
||||
void OnInitialized();
|
||||
|
||||
event EventHandler<object> OnOutput;
|
||||
event EventHandler<string> OnPaste;
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,22 @@ namespace FluentTerminal.RuntimeComponent.WebAllowedObjects
|
||||
public TerminalBridge(IxtermEventListener terminalEventListener)
|
||||
{
|
||||
_terminalEventListener = terminalEventListener;
|
||||
_terminalEventListener.OnOutput += _terminalEventListener_OnOutput;
|
||||
_terminalEventListener.OnOutput += OnOutput;
|
||||
_terminalEventListener.OnPaste += OnPaste;
|
||||
}
|
||||
|
||||
private void _terminalEventListener_OnOutput(object sender, object e)
|
||||
private void OnPaste(object sender, string e)
|
||||
{
|
||||
Task.Factory.StartNew(() => Paste?.Invoke(this, e));
|
||||
}
|
||||
|
||||
private void OnOutput(object sender, object e)
|
||||
{
|
||||
Task.Factory.StartNew(() => Output?.Invoke(this, e));
|
||||
}
|
||||
|
||||
public event EventHandler<object> Output;
|
||||
public event EventHandler<string> Paste;
|
||||
|
||||
public void InputReceived(string message)
|
||||
{
|
||||
@@ -42,7 +49,8 @@ namespace FluentTerminal.RuntimeComponent.WebAllowedObjects
|
||||
|
||||
public void DisposalPrepare()
|
||||
{
|
||||
_terminalEventListener.OnOutput -= _terminalEventListener_OnOutput;
|
||||
_terminalEventListener.OnOutput -= OnOutput;
|
||||
_terminalEventListener.OnPaste -= OnPaste;
|
||||
_terminalEventListener = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user