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

Suggestion for snippets #63

Closed
ghost opened this issue Jun 17, 2014 · 11 comments
Closed

Suggestion for snippets #63

ghost opened this issue Jun 17, 2014 · 11 comments

Comments

@ghost
Copy link

ghost commented Jun 17, 2014

Hi Tomas,
I would like to suggest adding API to create snippets. the idea is that those snippets would know if they are being selected, hovered over, etc. and a text area would know these snippets' locations, their style, etc. and probably have a property to report on which, if any, snippet is being clicked inside of or selected.

i implemented a very sketchy version, which half-works for the purpose of my project, but i thought such element type would be cool to have i richtextfx.

thanks !
Maher

@TomasMikula
Copy link
Member

Hi Maher,

how do you imagine such an API? How, for example, do you imagine to get/create an instance of a snippet and how would you use one?

@ghost
Copy link
Author

ghost commented Jun 18, 2014

Hi Tomas,
Here is a scenario

InlineCssTextArea richText = new InlineCssTextArea ();

//a snippet would need a text and style. I guess it might be called a
class, because it can be instaniated within a rich text area (inserted in
more than one place).
SnippetClass mySnippet = new SnippetClass("some text" , "-fx-font-size:
10;");

//I can insert a snippet into a rich text area
richText.insert(0, mySnippet.getInstance(0)); location and instance

//I would want to get all instances of a snippet and replace them

mySnippet.getInstances(richText), or
mySnippet.getInstance(richText).get(0).replace(newSnipppet);

or maybe the other way around

//find a certain snippet in this text
richText.getSnippet(mySnippet).get(0).replace(newSnippet);

//I can listen to the snippet properties... for example
mySnippet.getInstances().SetOnMouseEntered.....,
mySnippet.getInstances().setOnMouseClicked, setOnCaretCrossed (just making
up events
here)., mySnippet.getInstances().positionProperty().addListener(Changer
Listener)----> {get Snippet Index} etc...

or mySnippet.styleProperty() //since a style is true for all instances,..
it can be done at class level

//I also would want to do something , higlight snippets, in all text
area/...
For (SnippetInstance snippet: mySnippet.getInstances(){
IndexRange range = snippet.getIndexRange();
}

//or see how many snippet instances are inserted
richtext.getSnippetCount(mySnippet);
or

mySnippet.getCount(richText);//get snippets in this text area

//or things like
richText.remove(mySnippet.getInstances().get(0));
richText.removeAll(mySnippet.getInstances());

richText.getSnippetInstances(mySnippet); //this would get me a list of all
instances of this class,, and for each instance, I can get location, etc.

In this sense a snippet is a defined body of text, which can keep track of
the positions of its instances that are inserted in a text area. of course,
I would like to be able to redefine this snippet, by snippet.setText(), or
snippet.setStyle(), etc. and when updating the definition, all of them
would update.
I imagine that I can also use the content of a snippet to create new ones..
for example SnippetClass mySnippet2 = new
SnippetClass(mySnippet.getText(), mySnippet.getStyle());

This would allow me to do cool things like:

Find and replace all , or have snippets stored somewhere, and simply scroll
in snippets in text. for example, you have a certain slogan, or a project
name, and it is populated everywhere in your document. A typical use case
would be find all, replace, enter to confirm, under if you don't like,
redo, etc. I implemented a VERY sketchy version tat is based on crude text
search (remember when I asked you about if two styled documents match?)..
now I can do something like: replace all occurrences of this snippet in the
document by scrolling my mouse through my saved snippet list. so, replaced
4 user clicks with a scroll.

With a proper snippet class, I can do text highlighting, and keep track of
where snippets are being moved around the text as users add or remove
characters.

I could think of other cool interactions that can be facilitated by such
API.
For example, I could create a snippet for a body of text, or another rich
text area.. and use it as a reference. so something like..

richText.setSnippet(mySnippet);

richText2.insertSnippet(0, mySnippet.getInstance(0)); where you say, place
this reference at this location..

then I can probably add a hyper link.. so that for example double-clicking
on any instance of this snippet would load a text area, etc....

of course a richtext would be bale to removeAllSnippetClasses,
getAllSnippetClasses, etc....

I can keep going on with possible scenarios :) but I guess you get the idea!

Ps. these are mostly my imaginations :D

On Tue, Jun 17, 2014 at 7:19 PM, TomasMikula [email protected]
wrote:

Hi Maher,

how do you imagine such an API? How, for example, do you imagine to
get/create an instance of a snippet and how would you use one?


Reply to this email directly or view it on GitHub
#63 (comment)
.

@ghost
Copy link
Author

ghost commented Jun 23, 2014

Oh , another place that would highly benefit from such an API is in code area.. if you have a way to define text-entities, then you can then do things like refactoring a variable name in code area.

@TomasMikula
Copy link
Member

Hi Maher,

I see the usefulness of some of the scenarios. I'm not sure about SnippetClass though. What should happen when one snippet instance is edited in the text area? Should all instances of the same class change accordingly? If so, how would you unlink one instance from the snippet class to allow it to be edited independently?

@ghost
Copy link
Author

ghost commented Jul 7, 2014

hi Tomas, Maybe a factory?
Here is what i suggest.

If the caret hits a snippet instance, it gets highlighted or italicized or
maybe the caret shape changes. user can assign a right click action to
refactore or make orphan.
changing one snippet from the refactore will change the rest. they are
clones.

if i just type inside a snippet, like insert a space inside, it gets
orphaned or right click snd select orphan. .

what i did was store a snippet template to a side tree view and then assign
some right click actions like insert, remove. i did not any update method.

to create a snippet template you select text from the text area and either
'' save as new snippet template'' or '' save over existing template''. the
second option would display the numbers of existing snippets to override.
so this takes care if updating snippets.

my snippet implementation keeps breaking because of the way i am tracking
the caret. each inserted snippet (basically text with a range) listens to
the caret position change. this is coupled with a method that listens to
text length change. i use both methods to update the index range of the
instance. but its not working very well. it keeps breaking.

my other issue is when i replace all snippets, if snippets length is
different, the snippets would eat into the existing text after the insert
position . I tried delete then insert and then i tried replace but i
still don't have it working well.

i thought if this was implemented within richtextfx where positions are
tracked by the internal model, then things would be more accurate.

best,
maher
On Jul 7, 2014 5:54 AM, "TomasMikula" [email protected] wrote:

Hi Maher,

I see the usefulness of some of the scenarios. I'm not sure about
SnippetClass though. What should happen when one snippet instance is edited
in the text area? Should all instances of the same class change
accordingly? If so, how would you unlink one instance from the snippet
class to allow it to be edited independently?


Reply to this email directly or view it on GitHub
#63 (comment)
.

@TomasMikula
Copy link
Member

It's tricky to get right, especially when one edit triggers another. But there is no magically easy way to implement this in RichTextFX internally. As I noted in #66, StyledTexts don't track their positions in text. If I were to implement this, it would be on top of the API that is already available.

@ghost
Copy link
Author

ghost commented Jul 7, 2014

would a bounty be enough incentive? :) (there is one)!

On Mon, Jul 7, 2014 at 1:11 PM, TomasMikula [email protected]
wrote:

It's tricky to get right, especially when one edit triggers another. But
there is no magically easy way to implement this in RichTextFX internally.
As I noted in #66 #66,
StyledTexts don't track their positions in text. If I were to implement
this, it would be on top of the API that is already available.


Reply to this email directly or view it on GitHub
#63 (comment)
.

@TomasMikula
Copy link
Member

I noticed the bounty, thanks! But I cannot guarantee any timeline.

@ghost
Copy link
Author

ghost commented Jul 8, 2014

whenever you get to it!

@RobertBColton
Copy link

I'd just like to mention here for reference, I don't know if it should be a separate ticket or not but, bookmarks. The snippets could also serve as bookmarks to jump to specific identfiers/etc. Though that may be beyond the scope of RTFX.

@JordanMartinez
Copy link
Contributor

This is another issue that I believe should now be possible to implement on top of RTFX due to the added custom object support. Thus, I'm closing this.
Please reopen if you think otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants