open/close path changes

master
Mark MacKay 2021-10-21 17:43:39 -05:00
parent fc1027d545
commit 46c7a78324
2 changed files with 18 additions and 12 deletions

View File

@ -6,6 +6,12 @@
// changes which were implemented in Firefox 43 and Chrome 46. // changes which were implemented in Firefox 43 and Chrome 46.
(function() { "use strict"; (function() { "use strict";
// The polyfill only applies to browser environments with a `window` object
// (i.e. not node.js, workers, etc.). If included in one of these
// environments (such as when using 'react-dom/server'), simply return out
if (typeof window === 'undefined')
return;
if (!("SVGPathSeg" in window)) { if (!("SVGPathSeg" in window)) {
// Spec: http://www.w3.org/TR/SVG11/single-page.html#paths-InterfaceSVGPathSeg // Spec: http://www.w3.org/TR/SVG11/single-page.html#paths-InterfaceSVGPathSeg
window.SVGPathSeg = function(type, typeAsLetter, owningPathSegList) { window.SVGPathSeg = function(type, typeAsLetter, owningPathSegList) {

View File

@ -4629,6 +4629,11 @@ var pathActions = canvas.pathActions = function() {
return svgedit.path.path; return svgedit.path.path;
}, },
opencloseSubPath: function() { opencloseSubPath: function() {
const isNullish = (val) => {
return val === null || val === undefined;
};
const path = svgedit.path.path; const path = svgedit.path.path;
const selPts = path.selected_pts; const selPts = path.selected_pts;
// Only allow one selected node for now // Only allow one selected node for now
@ -4663,7 +4668,7 @@ var pathActions = canvas.pathActions = function() {
return true; return true;
}); });
if (openPt == null) { if (isNullish(openPt)) {
// Single path, so close last seg // Single path, so close last seg
openPt = path.segs.length - 1; openPt = path.segs.length - 1;
} }
@ -4707,7 +4712,6 @@ var pathActions = canvas.pathActions = function() {
// Find this sub-path's closing point and remove // Find this sub-path's closing point and remove
for (let i = 0; i < list.numberOfItems; i++) { for (let i = 0; i < list.numberOfItems; i++) {
const item = list.getItem(i); const item = list.getItem(i);
if (item.pathSegType === 2) { if (item.pathSegType === 2) {
// Find the preceding M // Find the preceding M
lastM = i; lastM = i;
@ -4723,19 +4727,15 @@ var pathActions = canvas.pathActions = function() {
} }
} }
let num = (index - lastM) - 1; //let num = (index - lastM) - 1;
//while (num--) {
while (num--) { // list.insertItemBefore(list.getItem(lastM), zSeg);
list.insertItemBefore(list.getItem(lastM), zSeg); //}
}
const pt = list.getItem(lastM); const pt = list.getItem(lastM);
// Make this point the new "M" // Make this point the new "M"
svgedit.path.replacePathSeg(2, lastM, [ pt.x, pt.y ]); svgedit.path.replacePathSeg(2, lastM, [ pt.x, pt.y ]);
// i = index; // i is local here, so has no effect; what was the intent for this?
path.init().selectPt(0); path.init().selectPt(0);
}, },
deletePathNode: function() { deletePathNode: function() {
@ -5927,7 +5927,7 @@ this.setSvgString = function(xmlString) {
var background = $("#canvas_background") var background = $("#canvas_background")
if (background.length) { if (background.length) {
var opacity = background.attr("fill-opacity") var opacity = background.attr("fill-opacity")
opacity = opacity ? parseInt(opacity)*100 : 100 opacity = opacity ? parseInt(opacity, 10)*100 : 100
fill = this.getPaint(background.attr("fill"), opacity, "canvas") fill = this.getPaint(background.attr("fill"), opacity, "canvas")
editor.paintBox.canvas.setPaint(fill) editor.paintBox.canvas.setPaint(fill)
} }