Giter Site home page Giter Site logo

Comments (3)

akash3456 avatar akash3456 commented on August 16, 2024

Is there any chance of an example please???

from avalonedit.

mike-ward avatar mike-ward commented on August 16, 2024

Sure.

In the OnLoad:

DataObject.AddPastingHandler(AvalonEditBox, OnPaste);

And then later:

private void OnPaste(object sender, DataObjectPastingEventArgs e)
{
    var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
    if (!isText) return;
    var text = (string)e.SourceDataObject.GetData(DataFormats.UnicodeText);

    if (Uri.IsWellFormedUri(text))
    {
        var dataObject = new DataObject();
        dataObject.SetData(DataFormats.UnicodeText, string.Format("<{0}>", text);
        e.DataObject = dataObject;
    }
}

To reproduce, drag and drop an image from a web browser. By default, AE will paste the link in. I want to modify the paste text to be surrounded by less than, greater than symbols (<link>). This is for use in my Markdown Editor (http://mike-ward.net/markdownedit).

If I create a new dataobject (as per the example) and return it, the original dataobject's text is used, not the modified text.

I can achieve my desired functionality by canceling the paste command and issuing a new paste with the modified text. It works but feels a bit wrong.

Hope that clarifies the issue.

from avalonedit.

mike-ward avatar mike-ward commented on August 16, 2024

For reference, here's how I'm currently working around the issue:

https://github.com/mike-ward/Markdown-Edit/blob/master/src/MarkdownEdit/Controls/Editor.xaml.cs#L141

from avalonedit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.