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

Blockmodification always inserts br after block #438

Open
ghost opened this issue Sep 20, 2023 · 4 comments
Open

Blockmodification always inserts br after block #438

ghost opened this issue Sep 20, 2023 · 4 comments

Comments

@ghost
Copy link

ghost commented Sep 20, 2023

Its troublesome to hit delete at blockend to remove this clutter. Please look into it. I strongly doubt this is a browser issue. All chromium browsers i tested on windows demonstrate the same issue. Win10. Edge. Chrome. Brave.

@neilj
Copy link
Member

neilj commented Sep 20, 2023

If you want me to look at something, please include steps to reproduce, the expected outcome, the actual outcome, and why this is causing a problem.

@ghost
Copy link
Author

ghost commented Sep 21, 2023

my squire instance is initialized like this when the dblclick event is fired on a div

new Squire(selection, {
	blockTag: 'P',
	blockAttributes: {/*not relevant */},
	tagAttributes: {
		ul : {/*not relevant */},
		li: {/*not relevant */}
	}
})

selection points to the container div

my formatting methods all look somewhat like this:

app.formatH2 = function(){
		if (!squire.hasFormat("h2")) {
			squire.modifyBlocks(function(fragment){
				fragment.querySelectorAll("h1,p,h3").forEach(function(block){
					const h = d.createElement("h2");
					h.append(...block.childNodes);
					block.replaceWith(h);					
					return h;
				})
				return fragment;
			})
			squire.focus();
		}
	}

Expected outcome is that a block level element such as the h$ and p is replaced by another block level element so that visually and element transforms into another paragraph type.
instead .modifyBlocks also inserts a br after the inserted element.

beforeclick:

<div contenteditable>
<p>content...</p>
</div>

afterclick:

<div contenteditable>
<h1>content...</h1>
<br>
</div>

My setup uses a toolbar button to trigger the modifyBlocks method.
my toolbar looks like this:

<div>
<button></button>
</div>

the buttons fire their events with a common "click" event handler with the useCapture set to false at all times.

@neilj
Copy link
Member

neilj commented Oct 2, 2023

I can't reproduce this, sorry.

@ghost
Copy link
Author

ghost commented Oct 2, 2023

Will you allow me to clean things up and try with your latest update?

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

No branches or pull requests

1 participant