Skip to content

Commit

Permalink
Fix logic for retrieving lastKnownElement
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpnielsen committed Apr 25, 2024
1 parent 2bb56f1 commit f728898
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,27 @@

// If an infinite editor is being closed then we reset the focus to the element that triggered the the overlay
if(closingEditor){

// If there is only one editor open, search for the "editor-info" inside it and set focus on it
// This is relevant when a property editor has been selected and the editor where we selected it from
// is closed taking us back to the first layer
// Otherwise set it to the last element in the lastKnownFocusedElements array
if(infiniteEditors && infiniteEditors.length === 1){
var editorInfo = infiniteEditors[0].querySelector('.editor-info');
if(infiniteEditors && infiniteEditors.length === 1 && editorInfo !== null) {
lastKnownElement = editorInfo;

// Clear the array
clearLastKnownFocusedElements();
}
var editorInfo = (infiniteEditors && infiniteEditors.length === 1)
? infiniteEditors[0].querySelector('.editor-info')

Check notice on line 97 in src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbfocuslock.directive.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/contrib)

✅ No longer an issue: Complex Conditional

FocusLock.link no longer has a complex conditional
: null;

if(editorInfo !== null){
lastKnownElement = editorInfo;

// Clear the array
clearLastKnownFocusedElements();
}
else {
var lastItemIndex = $rootScope.lastKnownFocusableElements.length - 1;
lastKnownElement = $rootScope.lastKnownFocusableElements[lastItemIndex];
else{
var lastIndex = $rootScope.lastKnownFocusableElements.length - 1;
lastKnownElement = $rootScope.lastKnownFocusableElements[lastIndex];

// Remove the last item from the array so we always set the correct lastKnowFocus for each layer
$rootScope.lastKnownFocusableElements.splice(lastItemIndex, 1);
// Remove the last item from the array so we always set the correct lastKnowFocus for each layer
$rootScope.lastKnownFocusableElements.splice(lastIndex, 1);

Check notice on line 111 in src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbfocuslock.directive.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/contrib)

✅ Getting better: Complex Method

FocusLock.link decreases in cyclomatic complexity from 30 to 28, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}

// Update the lastknowelement variable here
Expand Down

0 comments on commit f728898

Please sign in to comment.