Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Collapsing code causes issues with right-arrow navigation #3026

Closed
Rosseyn opened this issue Jul 21, 2014 · 8 comments
Closed

Collapsing code causes issues with right-arrow navigation #3026

Rosseyn opened this issue Jul 21, 2014 · 8 comments
Assignees
Labels
bug windows Issues that occur on Windows but not on other platforms.

Comments

@Rosseyn
Copy link

Rosseyn commented Jul 21, 2014

Windows 8.0, Atom v0.115.0, occurs in safe mode

To replicate: open a file (confirmed in php and js files), collapse a relatively good sized code block and move cursor below the collapsed block; now attempt to use the right arrow to navigate to the end of various longer lines of code/text.

The cursor stops in seemingly arbitrary places, and not in the same column of each line. Some lines might not allow right arrow navigation at all, some might do it all the way to the default 80 char line guide, generally somewhere in between though.

Not seeing any errors in dev tools console.

See here for video.

@benogle
Copy link
Contributor

benogle commented Jul 22, 2014

Are you using the react editor? If not, please enable it and try again: http://blog.atom.io/2014/07/02/moving-atom-to-react.html

@Rosseyn
Copy link
Author

Rosseyn commented Jul 22, 2014

Still occurs on v0.117 with react enabled.

@benogle
Copy link
Contributor

benogle commented Jul 22, 2014

Can you paste in a file that has this problem?

@Rosseyn
Copy link
Author

Rosseyn commented Jul 22, 2014

I was able to replicate the issue using this code by collapsing some of the larger code blocks and attempting to move cursor to the right on lines below the collapsed code.

'use strict';
/* create Controllers */
var createControllers = {};
createControllers.SwellCreateCtrl = function($scope, $location, $timeout, Swell, Field, Task, Tag) {
  $scope.browser = {placeholder : Modernizr.placeholder, history : Modernizr.history};
  $scope.page = {number : $location.path().search('/swelldetails/') > -1 ? 2 : 1 };
  $scope.page.page1valid = false;
  $scope.page.page2valid = false;
  $scope.page.validFields = {};
  $scope.page.validField = true;
  $scope.swellId = $('form#swell-create').data('swell-id');
  $scope.savehide = true;
  $scope.newTag= {};

  $scope.swell = Swell.get({swellId: $scope.swellId}, function(s) {
    $scope.save({field:'name', value:$scope.swell.name});
    if( !s.extraFieldTitle ) s.extraFieldTitle = 'Area for adding more information. (optional)';

    if( $scope.page.number == 1 ) {
      // Load existing information
      $scope.currentCategory = $scope.getCategoryName(s.category_id);

      // Validate populated fields
      var requiredFields = ['name', 'brief', 'problem', 'category_id'];
    }

    if( $scope.page.number == 2 ) {
      s.ask_amount = parseInt(s.ask_amount);
      s.days_of_work = parseInt(s.days_of_work);

      // Load existing information
      Tag.get({id: $scope.swell.id}, function(t) {
        $scope.tags = t.tags;
      });

      Task.get({swellId: $scope.swell.id}, function(t) {
        $scope.tasks = t.tasks;
        $scope.page.validFields.tasks = {valid: $scope.tasks.length > 0};
        $scope.tasks.push({});
      });

      // Show validation for populated fields
      var requiredFields = ['solution', 'fixed', 'ask_amount', 'expires', 'days_of_work', 'solvers', 'solvable'];
    }

    requiredFields.forEach(function(el, i, arr) {
      $scope.page.validFields[el] = {valid: !!s[el], errors: []}
    });

    if( !$scope.swellId ) {
      s.knowSolution = '';
      $scope.swell.id = s.id;
      if ($scope.browser.history) {
        $location.path('/swells/create/' + s.id);
      } else {
        window.location.href='' + baseUrl + 'swells/create/' + s.id;
      }
    }

    $scope.$watch('swell.expires', function(newValue, oldValue) {
      if( oldValue !== newValue ) {
        $scope.save({field:'expires', value:$scope.swell.expires}, 'enter-days-funding');
      }
    });

    $scope.$broadcast('swellUpdate', s);
  });

  $scope.isPage2Edited = function() {
    return $scope.swell.solution || $scope.swell.finePrint || $scope.swell.daysWork;
  };

  $scope.page1CanLaunch = function() {
    return $scope.page.page1valid && !$scope.fieldErrorCheck();
  };

  $scope.canLaunch = function() {
    return $scope.page.page1valid && $scope.page.page2valid && !$scope.fieldErrorCheck();
  };

  $scope.fieldErrorCheck = function() {
    // Spot check state of form after any changes are made, disallow continue
    // or launch if local errors are found even if there are no remote errors
    var keys = Object.keys($scope.page.validFields);
    var errors = keys.filter(function(field) {
      return !!$scope.page.validFields[field] &&
              !!$scope.page.validFields[field].errors &&
              Object.keys($scope.page.validFields[field].errors).length > 0;
    });
    return errors.length > 0;
  };

  $scope.onlyNumbers = function(e) {
    // Allow numbers, arrows, backspace, delete, tab and function keys
    if( (e.keyCode < 48 || e.keyCode > 57) &&
        !((e.keyCode == 46  || e.keyCode == 8     || e.keyCode == 9 ||
          (e.keyCode >= 37  && e.keyCode <= 40)   ||
          (e.keyCode >= 96  && e.keyCode <= 105)  ||
          (e.keyCode >= 112 && e.keyCode <= 123)  )) )
      e.preventDefault();
  };

  var sendTimeout,
      sendTimeoutDelay = 1000; // 1 second

  $scope.saveTimeout = function(data, name) {
    if( !!$scope.page.validFields[data.field] ) {
      $scope.page.validFields[data.field].saved = false;
    } else {
      $scope.page.validFields[data.field] = {saved : false};
    }
    $timeout.cancel(sendTimeout);
    sendTimeout = $timeout(function() {
      $scope.save(data,name);
    }, sendTimeoutDelay);
  };

  $scope.save = function(data, name) {
    if( !$scope.page.validFields[data.field] ) $scope.page.validFields[data.field] = {};
    if( !!$scope.page.validFields[data.field] && !!$scope.page.validFields[data.field].saved ) return;
    $timeout.cancel(sendTimeout);
    var field = Field.save({id: $scope.swell.id, field:data.field, value:data.value, page: $scope.page.number}, function(f) {
      !!$scope.page.validFields[data.field] ?
        $scope.page.validFields[data.field].saved = true :
        $scope.page.validFields[data.field] = {saved : true};

      $scope.page.validFields[data.field].valid = f.field_validity.valid;
      $scope.page.validFields[data.field].errors = f.field_validity.errors;
      $scope.page.page1valid = f.page1_validity.valid;
      $scope.page.page2valid = f.page2_validity.valid;

      if( !!name ) {
        var el = $('[name='+ name +']');
        if( f.field_validity.valid ) {
          $scope.page.validField = true;
          $scope.page.validFields[data.field].activeSaved = true;
          $timeout(function() {
            $scope.page.validFields[data.field].activeSaved = false;
          }, 4000);
        } else {
          $scope.page.validField = false;
          var fieldErrorText = f.field_validity.errors[f.field][0];
          el.parent().siblings('span.field-error').children('span.message-text')
            .text(fieldErrorText);
          $scope.page.validFields[data.field].activeError = true;
          $timeout(function() {
            $scope.page.validFields[data.field].activeError = false;
          }, 4000)
        }
      }
    });
  };

  $scope.$on('destroy', function(e) {$timeout.cancel()});

  /**
   * Page 1 functions
   */
  if( $scope.page.number == 1 ) {
    $scope.categories = {};
    $scope.setCategories = function(cats) {
      $scope.categories = cats;
    };

    $scope.currentCategory = false;
    $scope.getCategoryName = function(id) {
      var currentCat = $scope.categories.filter(function(cat) {
        return cat.categoryId == id;
      });
      return currentCat.length > 0 ? currentCat[0].name : 'Pick one';
    };

    $scope.categoryFlags = function () {
      return !!$scope.page.validFields.category_id && !!$scope.page.validFields.category_id.valid;
    };

    $scope.locationUpdate = function() {
      $scope.swell.latitude = $('#searchLocation').data('latitude');
      $scope.swell.longitude = $('#searchLocation').data('longitude');
      $scope.swell.zip = !!$('#searchLocation').data('zip') ? $('#searchLocation').data('zip') : null;
      $scope.swell.city = !!$('#searchLocation').data('city') ? $('#searchLocation').data('city') : null;
      $scope.swell.state = !!$('#searchLocation').data('state') ? $('#searchLocation').data('state') : null;
      Field.save({id: $scope.swell.id, field:'latitude', value:$scope.swell.latitude, page: $scope.page.number},
        function(f) {
          if( !!f.page1_validity ) $scope.page.page1valid = f.page1_validity.valid;
          if( !!f.page2_validity ) $scope.page.page2valid = f.page2_validity.valid;
          $scope.page.validFields[f.field] = f.field_validity;
          Field.save({id: $scope.swell.id, field:'longitude', value:$scope.swell.longitude, page: $scope.page.number}, function(fi) {
            if( !!fi.page1_validity ) $scope.page.page1valid = fi.page1_validity.valid;
            if( !!fi.page2_validity ) $scope.page.page2valid = fi.page2_validity.valid;
            $scope.page.validFields[fi.field] = fi.field_validity;

            Field.save({id: $scope.swell.id, field:'city', value:$scope.swell.city, page: $scope.page.number}, function(fie) {
              $scope.page.validFields[fie.field] = fie.field_validity;
              Field.save({id: $scope.swell.id, field:'state', value:$scope.swell.state, page: $scope.page.number}, function(fiel) {
                $scope.page.validFields[fiel.field] = fiel.field_validity;
              });
            });
          });
        }
      );
    };

    $scope.continue = function() {
      Swell.continue({id: $scope.swell.id}, function(s) {
        if( s.errors ) {
          // Report errors to user
        } else {
          if($scope.page1CanLaunch()) {
            window.location = "/swells/create/swelldetails/" + $scope.swell.id;
          }
        }
      })
    };
  }


  $scope.launch = function(e) {
    e.preventDefault();
    Swell.launch({id: $scope.swell.id}, function(s) {
      $scope.swell.slug = s.slug;
      if( s.errors ) {
        // Report errors to user
      } else {
        if($scope.page1CanLaunch()) { 
          window.location = "/swells/"+ s.slug;
        }
      }
    })
  };

  /**
   * Page 2 functions
   */
  $scope.addTask = function() {
    $scope.tasks.push({});
  };

  var taskTimeoutDelay = 1000; // 1 second
  $scope.taskSave = function(task) {
    $timeout.cancel(task.timeout);
    Task.save({id: task.id, swellId: $scope.swell.id, description: task.description}, function(t) {
      task.id = t.taskId;
      var validTaskCount = $scope.validTaskCount();
      if( t.action == 'create' && $scope.tasks.length - validTaskCount < 1 )
        $scope.addTask();
    });
  };

  $scope.taskSaveTimeout = function(task) {
    $timeout.cancel(task.timeout);
    task.timeout = $timeout(function() {
      $scope.taskSave(task);
    }, taskTimeoutDelay)
  };

  $scope.taskDelete = function(task) {
    $timeout.cancel(task.timeout);
    if( !!task.id ) {
      Task.delete({id: task.id, swellId: $scope.swell.id}, function(t) {
        $scope.tasks.splice($scope.tasks.indexOf(task), 1);
        $scope.validTaskCount();
      });
    } else {
      $scope.tasks.splice($scope.tasks.indexOf(task), 1);
    }
  };

  $scope.validTaskCount = function() {
    var savedTasks = $scope.tasks.filter(function(task) {
      return !!task.id;
    })

    $scope.page.validFields.tasks.valid = savedTasks.length > 0;
    return savedTasks.length;
  };

  $scope.taskKeystroke = function(e, task) {
    if( e.keyCode == 9 || e.keyCode == 13) {
      e.preventDefault();
      $scope.taskSave(task);
    }
  };

  $scope.tagToggle = function(tag) {
    if( !tag.isSwellTag ) {
      Tag.add({swellId: $scope.swell.id, tagId: tag.tagId}, function(t) {
        tag.isSwellTag = true;
      });
    } else {
      Tag.delete({swellId: $scope.swell.id, tagId: tag.tagId}, function(t) {
        tag.isSwellTag = false;
      });
    }
  };

  $scope.addDaysToDate = function() {
    var days = $scope.swell.daysFunding;
    var dat = new Date();
    dat.setDate(dat.getDate() + days * 1.0);
    var dateVal = dat.getUTCFullYear() + '-' + padDate(dat.getUTCMonth()+1) + '-' + padDate(dat.getUTCDate());
    $scope.swell.expires = dateVal;
  };

  $scope.solverCheck = function() {
    if( $scope.swell.fixed == 1 ) {
      return  !!$scope.page.validFields.ask_amount    && !!$scope.page.validFields.ask_amount.valid &&
              !!$scope.page.validFields.expires       && !!$scope.page.validFields.expires.valid;
    } else {
      return  !!$scope.page.validFields.days_of_work  && !!$scope.page.validFields.days_of_work.valid;
    }
  };

  $scope.launchFull = function(e) {
    e.preventDefault();
    Swell.launchFull({id: $scope.swell.id}, function(s) {
      $scope.swell.slug = s.slug;
      if( s.errors ) {
        // Report errors to user
      } else {
        if($scope.canLaunch()) {
          window.location = "/swells/"+ s.slug;
        }
      }
    });
  };

};

createControllers.DemoFileUploadController = function ($scope, $http) {
  var url = $('#fileupload').attr('action');
  var xsrfToken = $('#fileupload').data('xsrf-token');
  $scope.options = {
    url: url,
    minFileSize: 2000,
    maxFileSize: 5000000,
    maxNumberOfFiles: 18,
    headers: { 'X-XSRF-TOKEN': xsrfToken },
    autoUpload: true,
    formData: {
      type: 'initiatives'
    }
  };

  // TODO :: Disable image upload button until swell.id is available

  $scope.$on('swellUpdate', function (e,data) {
    $scope.options.formData.id = data.id;
    $scope.swell = data;
    $scope.disabled = !$scope.swell.id || $scope.swell.id < 1;
  });

  $scope.$parent.swell.$promise.then(function(s) {
    $scope.loadingFiles = true;
    $http.get(url + '?id=' + s.id + '&type=initiatives')
      .then(
      function (response) {
        $scope.loadingFiles = false;
        $scope.queue = response.data.files || [];
        if( $scope.queue.length > 0 ) $scope.page.validFields.featured = true;
        if( !!s.featured ) {
          var featured = $scope.queue.filter(function(image) {
            return image.name == s.featured;
          });
          var first = $scope.queue.indexOf(featured[0]);
          $scope.queue.splice(first, 1);
          $scope.queue.unshift(featured[0]);
        }
      },
      function () {
        $scope.loadingFiles = false;
      }
    );
  });
};

createControllers.FileDestroyController = function ($scope, $http) {
  $scope.$parent.swell.$promise.then(function(s) {
    $scope.swell = s;
  });
  var file = $scope.file,
    state;
  if (file.url) {
    file.$state = function () {
      return state;
    };
    file.$destroy = function () {
      state = 'pending';
      return $http({
        url: file.deleteUrl,
        method: file.deleteType
      }).then(
        function () {
          state = 'resolved';
          $scope.clear(file);
          var remaining = $scope.queue.filter(function(image) {
            return !!image.url;
          });
          $scope.page.validFields['featured'] = remaining.length > 0;
        },
        function () {
          state = 'rejected';
          var input = $("#main").find("div.preview span.destroy");

          // Clear previous errors
          input.trigger('error-resolve');

          var error = {
            "el" : input,
            "msg" : 'This image is currently in use.',
            "id" : $scope.swell.id
          };

          // Trigger event handler that adds error and resolve handler to error container
          $('#main-error-container').trigger('error-report', error).show();
          smoothScrollTo('#main-error-container', 150);

        }
      );
    };
    file.$duty = function() {
      state = 'pending';
      return $http({
        url: '/api/initiative/image?id='+ $scope.swell.id + '&image='+ file.name + '&type=featured',
        method: 'PUT'
      }).then(
        function() {
          //success
          $scope.swell.featured = file.name;
        },
        function() {
          //fail
        }
      )
    };
  } else if (!file.$cancel && !file._index) {
    file.$cancel = function () {
      $scope.clear(file);
    };
  }

  $scope.$on('swellUpdate', function (e,data) {
    $scope.swellId = data.id;
  });

};

create.controller(createControllers);

@benogle benogle self-assigned this Jul 23, 2014
@benogle
Copy link
Contributor

benogle commented Jul 25, 2014

I cant reproduce this. Looks like you're using vim mode. Can you disable vim mode and try again?

@benogle
Copy link
Contributor

benogle commented Jul 25, 2014

If it still happens, tell me exactly which lines to fold in the provided code block, and exactly which line it messes up.

@Rosseyn
Copy link
Author

Rosseyn commented Jul 30, 2014

I had thought running in safe mode would disable vim, I did so manually and it does appear that vim mode is causing this issue.

@lock
Copy link

lock bot commented Jan 25, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

@lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug windows Issues that occur on Windows but not on other platforms.
Projects
None yet
Development

No branches or pull requests

3 participants